一、stdlib.h和cstdlib的區別
轉載:https://zhidao.baidu.com/question/1757183223487622988.html
C語言中是有 #include <stdlib.h> 的。 這是C語言標准的包含庫的頭文件stdlib.h的語句。
在代碼中引用此句后,就可以使用stdlib.h中的函數,而不會出現未聲明的警告。
stdlib.h是C語言庫頭文件之一,包含了以下函數:
1 字符串轉換為數字的函數,包括atoi, atof, strtol等。
2 隨機數函數,包括srand, rand等。
3 內存分配釋放函數,如malloc,calloc,realloc,free等。
4 程序運行控制函數,如exit, abort等。
5 系統訪問相關函數,如printenv, setenv,system等。
6 常用算法函數,如qsort, bsearch, abs,div等。
在C++中也可以使用#include <stdlib.h>,因為C++兼容了C語言中的操作。
不過一般更推薦使用C++風格的頭文件,即#include <cstdlib>。
cstdlib實現了stdlib.h中的所有功能,不過是按照C++的方式寫的,所以與C++語言可以更好的配合。
二、stdlib.h和stdio.h的區別
轉載:https://zhidao.baidu.com/question/339948129.html
(一)定位不同
1、stdlib.h,是 standard library 標准庫頭文件,定位在通用工具函數。
2、stdio.h,是 standard input&output 標准輸入輸出頭文件,定位在標准的輸入輸出工具函數。
(二)封裝函數不同
1、stdlib.h主要封裝了malloc()、calloc()、realloc()、free()、system()、atoi()、atol()、rand()、srand()、exit()等函數。
2、stdio.h主要封裝了getchar()、putchar()、scanf()、printf()、gets()、puts()、sprintf()等函數。
(三)定義類型不同
1、stdlib.h定義了size_t、wchar_t、div_t、ldiv_t和lldiv_t五種類型。
2、stdio沒有定義類型。
