最近有朋友問了一下C++中的這個問題,我把它記錄下來了,供大家分享和交流!
#include <iostream>
...
std::cout << ...
或者
#include <iostream>
using namespace std;
cout << ...
這樣寫就是正確的,在程序的開頭加入以下代碼:
using namespace std;
這樣就不用在程序體內加入很多的std::這樣的域運算符了.
在VC++中如果
#include "iostream.h"
.....
std::out<<........
就會報錯error C2653: 'std' : is not a class or namespace name
舊標準是:<iostream.h> 不必using namespace std;
新標準是:<iostream> 要有using namespace std;
iostream.h裏沒有std空間,只有iostream裏有