2 回答

TA貢獻(xiàn)1820條經(jīng)驗 獲得超9個贊
#include <iostream.h>非標(biāo)準(zhǔn)輸入輸出流
#include <iostream>標(biāo)準(zhǔn)輸入輸出流
C++中為了避免名字定義沖突,特別引入了“名字空間的定義”,即namespace。
當(dāng)代碼中用<iostream.h>時,輸出可直接引用cout<<x;//<iostream.h>繼承C語言的標(biāo)準(zhǔn)庫文件,未引入名字空間定義,所以可直接使用。
當(dāng)代碼中引入<iostream>時,輸出需要引用std::cout<<x;如果還是按原來的方法就會有錯。
iostream.h是input output stream的簡寫,意思為標(biāo)準(zhǔn)的輸入輸出流頭文件。它包含:
(1)cin>>"要輸入的內(nèi)容"
(2)cout<<"要輸出的內(nèi)容"
這兩個輸入輸出的方法需要#include<iostream>頭文件來聲明。
iostream 庫的基礎(chǔ)是兩種命名為 istream 和 ostream 的類型,分別表示輸入流和輸出流。流是指要從某種 IO 設(shè)備上讀出或?qū)懭氲淖址蛄小?/p>
擴展資料:
iostream和iostream.h的用法
使用<iostream>和命名空間
#include <iostream>
using namespace std;
int main()
{
cout<<"<iostream> need to use namespace std!/n";
return 0;
}
輸出:
<iostream> need to use namespace std!
Press any key to continue
使用<iostream.h>,不引入命名空間
#include <iostream.h>
//using namespace std;
int main()
{
cout<<"<iostream> need to use namespace std!/n";
return 0;
}
輸出:
<iostream> need to use namespace std!
Press any key to continue

TA貢獻(xiàn)1851條經(jīng)驗 獲得超4個贊
#include <iostream.h>非標(biāo)準(zhǔn)輸入輸出流
#include <iostream>標(biāo)準(zhǔn)輸入輸出流
C++中為了避免名字定義沖突,特別引入了“名字空間的定義”,即namespace。
當(dāng)代碼中用<iostream.h>時,輸出可直接引用cout<<x;//<iostream.h>繼承C語言的標(biāo)準(zhǔn)庫文件,未引入名字空間定義,所以可直接使用。
當(dāng)代碼中引入<iostream>時,輸出需要引用std::cout<<x;如果還是按原來的方法就會有錯。
使用<iostream>時,引入std::有以下方法:
1.
using namespace std;
cout<<x;
2.
using std::cout;
cout<<x;
3.
最基本的std::cout<<x;
這回你該知道為什么通常用#include <iostream>時,
要用using namespace std;了吧。如果你不用這個,就要在使用cout時,用后兩種方法了。
其他頭文件也是同樣的道理。
(有“.h”的就是非標(biāo)準(zhǔn)的,C的標(biāo)準(zhǔn)庫函數(shù),無“.h”的,就要用到命令空間,是C++的。還有一部分不完全是有“.h”和沒“.h”的差別。例如:math.h和cmath)
- 2 回答
- 0 關(guān)注
- 409 瀏覽
添加回答
舉報