中包含了iostream頭文件我試圖編譯下面的簡單程序。但是,這不是編譯&給出了錯誤:錯誤:'cout':未聲明的標識符;儘管我已經在程序
error C2065: 'cout' : undeclared identifier
我要問你,爲什麼,雖然我已經包含在裏面iostream
頭文件這個程序不能正常工作?
#include <iostream>
void function(int) { cout << 「function(int) called」 << endl; }
void function(unsigned int) { cout << 「function(unsigned int) called」 << endl; }
int main()
{
function(-2);
function(4);
return 0;
}
在此先感謝。
僅使用'std :: cout'而不是'cout'。在'namespace std'中使用的所有內容之前追加'std ::'。 – sgarizvi
或者在這樣的情況下 - 當你編寫一個非常簡單的程序時,你總是可以在'#include'下面的某個地方寫'using namespace std;'。它會通知編譯器在std命名空間中查找'cout',從而允許你的'cout'工作。 雖然這被認爲是不好的做法。 –
避免'使用命名空間標準;'。這是保證有一天你會咬你的。如果你不想輸入'std :: cout',可以使用'std :: cout',但將它限制在一個小範圍內,並且不要在頭文件中使用它。 – juanchopanza