C ++ cout给出未声明的标识符 [英] C++ cout gives undeclared identifier
问题描述
所以,我有这个问题。为什么cout throws
错误C2065:'cout':undeclared identifier
pre>
我使用Visual Studio 2012作为IDE,我正在写一个学校项目。除了一个示例文件,我有一切都做。所以我想在屏幕上这样写:
#includeiostream
#includestdafx .h
using namespace std;
int main()
{
cout<<example;
return 0;
}
所以问题是cout ... printf工作正常,但我想使用cout。
编辑:
我改变了到<>但它不是帮助。解决方案
切换文件并将第二个include转换为
#includestdafx.h
#include< iostream>
请参阅此信息了解详情。
So, I have this question. Why does cout throws
error C2065: 'cout' : undeclared identifier
I am using Visual Studio 2012 as an IDE and I am writing a school project. I have everything done except an example file. So I am trying to write something on the screen like this:
#include "iostream" #include "stdafx.h" using namespace std; int main() { cout<<"example"; return 0; }
So the problem is with cout... printf works fine, but I want to use cout.
EDIT: I've changed "" to <> but it is not helping. Also I am using this code only for example... This is not the whole project.
解决方案
stdafx.h
shall be the first include directive in your source file.Switch files and convert the second include to
<>
, as other suggested.#include "stdafx.h" #include <iostream>
See this post for more information.
这篇关于C ++ cout给出未声明的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!