問題描述
我正在處理我的編程任務的驅動程序"部分,但我不斷收到這個荒謬的錯誤:
I am working on the 'driver' part of my programing assignment and i keep getting this absurd error:
錯誤 C2065:'cout':未聲明的標識符
error C2065: 'cout' : undeclared identifier
我什至嘗試過使用 std::cout 但我收到另一個錯誤消息:IntelliSense: namespace "std" has no member "cout" 當我有聲明 using namespace std,包括 iostream + 我什至嘗試使用 ostream
I have even tried using the std::cout but i get another error that says: IntelliSense: namespace "std" has no member "cout" when i have declared using namespace std, included iostream + i even tried to use ostream
我知道這是一個標準的菜鳥問題,但這讓我很難過,而且我是個新手(意思是:我以前編程過......)
I know it's a standard noob question but this has stumped me and I'm a novice (meaning: I've programed before...)
#include <iostream>
using namespace std;
int main () {
cout << "hey" << endl;
return 0;
}
我使用的是 Visual Studio 2010 并運行 Windows 7.所有 .h 文件都有使用命名空間 std"并包括 iostream 和 ostream.
I'm using Visual Studio 2010 and running Windows 7. All of the .h files have "using namespace std" and include iostream and ostream.
推薦答案
在 Visual Studio 中,您必須 #include "stdafx.h"
并且是 cpp 文件的第一個包含. 例如:
In Visual Studio you must #include "stdafx.h"
and be the first include of the cpp file. For instance:
這些不起作用.
#include <iostream>
using namespace std;
int main () {
cout << "hey" << endl;
return 0;
}
#include <iostream>
#include "stdafx.h"
using namespace std;
int main () {
cout << "hey" << endl;
return 0;
}
這就行了.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main () {
cout << "hey" << endl;
return 0;
}
這里有一個關于 stdafx.h 標頭功能的很好的答案.
這篇關于錯誤 C2065:“cout":未聲明的標識符的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!