c++中#include中都能加什麼?有什麼用?

這裏需要注意include的兩種不同寫法,#include<***.h>和#include"***.h"
採用"< >"方式進行包含的頭文件表示讓編譯器在編譯器的預設標準路徑下去搜索相應的頭文件,如果找不到則報錯。
例如:VS2008的安裝目錄\Microsoft Visual Studio 9.0\VC\include下面就包含了標準庫的頭文件。
第二種方式表示先在工程所在路徑下搜索,如果失敗,再到系統標準路徑下搜索。
所以,特別要注意的是,如果是標準庫頭文件,那麼既可以採用<>的方式,又可以採用" "的方式,而用戶自定義的頭文件只能採用" "的方式。
例如,如下這種方式是正確的:
#include  <iostream>		效率較高
#include "iostream"		效率較低
如下這種方式是不正確的:
#include<diy.h>   diy.h是我們自己創建的頭文件

安裝問題中的格式,能加的所有文件如下:
A、傳統 C++:
#include <assert.h>    //設定插入點
#include <ctype.h>     //字符處理
#include <errno.h>     //定義錯誤碼
#include <float.h>     //浮點數處理
#include <fstream.h>    //文件輸入/輸出
#include <iomanip.h>    //參數化輸入/輸出
#include <iostream.h>   //數據流輸入/輸出
#include <limits.h>    //定義各種數據類型最值常量
#include <locale.h>    //定義本地化函數
#include <math.h>     //定義數學函數
#include <stdio.h>     //定義輸入/輸出函數
#include <stdlib.h>    //定義雜項函數及內存分配函數
#include <string.h>    //字符串處理
#include <strstrea.h>   //基於數組的輸入/輸出
#include <time.h>     //定義關於時間的函數
#include <wchar.h>     //寬字符處理及輸入/輸出
#include <wctype.h>    //寬字符分類

B、標準 C++ (與上方相同的文件不再註釋)
#include <algorithm>    //STL 通用算法
#include <bitset>     //STL 位集容器
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>     //複數類
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>      //STL 雙端隊列容器
#include <exception>    //異常處理類
#include <fstream>
#include <functional>   //STL 定義運算函數(代替運算符)
#include <limits>
#include <list>      //STL 線性列表容器
#include <map>       //STL 映射容器
#include <iomanip>
#include <ios>       //基本輸入/輸出支持
#include <iosfwd>     //輸入/輸出系統使用的前置聲明
#include <iostream>
#include <istream>     //基本輸入流
#include <ostream>     //基本輸出流
#include <queue>      //STL 隊列容器
#include <set>       //STL 集合容器
#include <sstream>     //基於字符串的流
#include <stack>      //STL 堆棧容器    
#include <stdexcept>    //標準異常類
#include <streambuf>    //底層輸入/輸出支持
#include <string>     //字符串類
#include <utility>     //STL 通用模板類
#include <vector>     //STL 動態數組容器
#include <cwchar>
#include <cwctype>

C、C99 增加的:
#include <complex.h>   //複數處理
#include <fenv.h>    //浮點環境
#include <inttypes.h>  //整數格式轉換
#include <stdbool.h>   //布爾環境
#include <stdint.h>   //整型環境
#include <tgmath.h>   //通用類型數學宏
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章