1. 程式人生 > >c/c++常用標頭檔案及函式彙總

c/c++常用標頭檔案及函式彙總

C/C++標頭檔案一覽

C

#include <assert.h>    //設定插入點
#include <ctype.h>     //字元處理
#include <errno.h>     //定義錯誤碼
#include <float.h>     //浮點數處理
#include <iso646.h>        //對應各種運算子的巨集
#include <limits.h>    //定義各種資料型別最值的常量
#include <locale.h>    //定義本地化C函式
#include <math.h>     //定義數學函式
#include <setjmp.h> //異常處理支援 #include <signal.h> //訊號機制支援 #include <stdarg.h> //不定引數列表支援 #include <stddef.h> //常用常量 #include <stdio.h>     //定義輸入/輸出函式 #include <stdlib.h>    //定義雜項函式及記憶體分配函式 #include <string.h>    //字串處理 #include <time.h>     //定義關於時間的函式
#include <wchar.h>     //寬字元處理及輸入/輸出 #include <wctype.h>    //寬字元分類 傳統C++ #include <fstream.h>    //改用<fstream> #include <iomanip.h>    //改用<iomainip> #include <iostream.h>   //改用<iostream> #include <strstrea.h>   //該類不再支援,改用<sstream>中的stringstream ———————————————————————————————— 標準C++  #include <algorithm>    //STL 通用演算法
#include <bitset>     //STL 位集容器 #include <cctype> //字元處理 #include <cerrno>      //定義錯誤碼 #include <cfloat>     //浮點數處理 #include <ciso646> //對應各種運算子的巨集 #include <climits>     //定義各種資料型別最值的常量 #include <clocale>     //定義本地化函式 #include <cmath>      //定義數學函式 #include <complex>     //複數類 #include <csignal> //訊號機制支援 #include <csetjmp> //異常處理支援 #include <cstdarg> //不定引數列表支援 #include <cstddef> //常用常量 #include <cstdio>      //定義輸入/輸出函式 #include <cstdlib>     //定義雜項函式及記憶體分配函式 #include <cstring>     //字串處理 #include <ctime>      //定義關於時間的函式 #include <cwchar>      //寬字元處理及輸入/輸出 #include <cwctype>     //寬字元分類 #include <deque>      //STL 雙端佇列容器 #include <exception>    //異常處理類 #include <fstream>     //檔案輸入/輸出 #include <functional>   //STL 定義運算函式(代替運算子) #include <limits>      //定義各種資料型別最值常量 #include <list>      //STL 線性列表容器 #include <locale> //本地化特定資訊 #include <map>       //STL 對映容器 #include <memory> //STL通過分配器進行的記憶體分配 #include<new> //動態記憶體分配 #include <numeric> //STL常用的數字操作 #include <iomanip>     //引數化輸入/輸出 #include <ios>       //基本輸入/輸出支援 #include <iosfwd>     //輸入/輸出系統使用的前置宣告 #include <iostream>    //資料流輸入/輸出 #include <istream>     //基本輸入流 #include <iterator> //STL迭代器 #include <ostream>     //基本輸出流 #include <queue>      //STL 佇列容器 #include <set>       //STL 集合容器 #include <sstream>     //基於字串的流 #include <stack>      //STL 堆疊容器 #include <stdexcept>    //標準異常類 #include <streambuf>    //底層輸入/輸出支援 #include <string>     //字串類 #include <typeinfo> //執行期間型別資訊 #include <utility>     //STL 通用模板類 #include <valarray> //對包含值的陣列的操作 #include <vector>     //STL 動態陣列容器 ———————————————————————————————— C99增加的部分 #include <complex.h>   //複數處理 #include <fenv.h>    //浮點環境 #include <inttypes.h>  //整數格式轉換 #include <stdbool.h>   //布林環境 #include <stdint.h>   //整型環境 #include <tgmath.h>   //通用型別數學巨集 標頭檔案 ctype.h

字元處理函式: 本類別函式用於對單個字元進行處理,包括字元的類別測試和字元的大小寫轉換

字元測試是否字母和數字 isalnum
是否字母 isalpha
是否控制字元 iscntrl
是否數字 isdigit
是否可顯示字元(除空格外) isgraph
是否可顯示字元(包括空格) isprint
是否既不是空格,又不是字母和數字的可顯示字元 ispunct
是否空格 isspace
是否大寫字母 isupper
是否16進位制數字(0-9,A-F)字元 isxdigit
字元大小寫轉換函式 轉換為大寫字母 toupper
轉換為小寫字母 tolower

標頭檔案 local.h

地區化: 本類別的函式用於處理不同國家的語言差異。

地區控制 地區設定 setlocale
數字格式約定查詢 國家的貨幣、日期、時間等的格式轉換 localeconv

標頭檔案 math.h

數學函式: 本分類給出了各種數學計算函式,必須提醒的是ANSIC標準中的資料格式並不符合IEEE754標準,一些C語言編譯器卻遵循IEEE754(例如frinklin C51)

反餘弦 acos
反正弦 asin
反正切 atan
反正切2 atan2
餘弦 cos
正弦 sin
正切 tan

雙曲餘弦 cosh
雙曲正弦 sinh
雙曲正切 tanh

指數函式 exp
指數分解函式 frexp
乘積指數函式 fdexp
自然對數 log
以10為底的對數 log10
浮點數分解函式 modf

冪函式 pow
平方根函式 sqrt

求下限接近整數 ceil
絕對值 fabs
求上限接近整數 floor
求餘數 fmod

標頭檔案 setjmp.h io.h

本分類函式用於實現在不同底函式之間直接跳轉程式碼。

儲存呼叫環境 setjmp
恢復呼叫環境 longjmp

標頭檔案 signal.h

訊號處理: 該分類函式用於處理那些在程式執行過程中發生例外的情況。

指定訊號處理函式 signal
傳送訊號 raise

標頭檔案 stdarg.h

可變引數處理: 本類函式用於實現諸如printf,scanf等引數數量可變底函式。

可變引數訪問巨集
可變引數開始巨集 va_start
可變引數結束巨集 va_end
可變引數訪問巨集 訪問下一個可變引數巨集 va_arg

標頭檔案 stdio.h

輸入輸出函式:該分類用於處理包括檔案、控制檯等各種輸入輸出裝置,各種函式以“流”的方式實現

刪除檔案 remove
修改檔名稱 rename
生成臨時檔名稱 tmpfile
得到臨時檔案路徑 tmpnam
檔案訪問 關閉檔案 fclose
重新整理緩衝區 fflush
開啟檔案 fopen
將已存在的流指標和新檔案連線 freopen
設定磁碟緩衝區 setbuf
設定磁碟緩衝區 setvbuf

格式化輸入與輸出函式
格式輸出 fprintf
格式輸入 fscanf
格式輸出(控制檯) printf
格式輸入(控制檯) scanf
格式輸出到緩衝區 sprintf
從緩衝區中按格式輸入 sscanf
格式化輸出 vfprintf
格式化輸出 vprintf
格式化輸出 vsprintf

字元輸入輸出函式
輸入一個字元 fgetc
字串輸入 fgets
字元輸出 fputc
字串輸出 fputs
字元輸入(控制檯) getc
字元輸入(控制檯) getchar
字串輸入(控制檯) gets
字元輸出(控制檯) putc
字元輸出(控制檯) putchar
字串輸出(控制檯) puts
字元輸出到流的頭部 ungetc

直接輸入輸出
直接流讀操作 fread
直接流寫操作 fwrite

檔案定位函式
得到檔案位置 fgetpos
檔案位置移動 fseek
檔案位置設定 fsetpos
得到檔案位置 ftell
檔案位置復零位 remind

錯誤處理函式
錯誤清除 clearerr
檔案結尾判斷 feof
檔案錯誤檢測 ferror
得到錯誤提示字串 perror

標頭檔案 stdlib.h

實用工具函式: 本分類給出了一些函式無法按以上分類,但又是程式設計所必須要的。

字串轉換函式
字串轉換為整數 atoi
字串轉換為長整數 atol
字串轉換為浮點數 strtod
字串轉換為長整數 strtol
字串轉換為無符號長整型 strtoul

偽隨機序列產生函式
產生隨機數 rand
設定隨機函式的起動數值 srand

儲存管理函式
分配儲存器 calloc
釋放儲存器 free
儲存器分配 malloc
重新分配儲存器 realloc

環境通訊
中止程式 abort
退出程式執行,並清除環境變數 atexit
退出程式執行 exit
讀取環境引數 getenv
程式掛起,臨時執行一個其他程式 system
搜尋和排序工具 二分查詢(資料必須已排序) bsearch
快速排序 qsort
整數運算函式 求絕對值 abs
得到除法運算底商和餘數 div
求長整形底絕對值 labs
求長整形除法的商和餘數 ldiv
多位元組字元函式 得到多位元組字元的位元組數 mblen
得到多位元組字元的位元組數 mbtowc
多位元組字元轉換 wctomb
多位元組字元的字串操作 將多位元組串轉換為整數陣列 mbstowcs
將多位元組串轉換為字元陣列 mcstowbs

標頭檔案 string.h

字串處理: 本分類的函式用於對字串進行合併、比較等操作

字串拷貝 塊拷貝(目的和源儲存區不可重疊) memcpy
塊拷貝(目的和源儲存區可重疊) memmove
串拷貝 strcpy
按長度的串拷貝 strncpy
字串連線函式 串連線 strcat
按長度連線字串 strncat
串比較函式 塊比較 memcmp
字串比較 strcmp
字串比較(用於非英文字元) strcoll
按長度對字串比較 strncmp
字串轉換 strxfrm
字元與字串查詢 字元查詢 memchr
字元查詢 strchr
字串查詢 strcspn
字串查詢 strpbrk
字串查詢 strspn
字串查詢 strstr
字串分解 strtok
雜類函式 字串設定 memset
錯誤字串對映 strerror
求字串長度 strlen

標頭檔案 time.h

日期和時間函式: 本類別給出時間和日期處理函式

時間操作函式得到處理器時間 clock
得到時間差 difftime
設定時間 mktime
得到時間 time
時間轉換函式 得到以ASCII碼錶示的時間 asctime
得到字串表示的時間 ctime
得到指定格式的時間 strftime

序號 庫類別 標頭檔案

1 錯誤處理 errno.h
2 字元處理 ctyphe.
3 地區化 local.h
4 數學函式 math.h
5 訊號處理 signal.h
6 輸入輸出 stdio.h
7 實用工具程式 stdlib.h
8 字串處理 string.h