C++ 错误C2065:&x27;cout';:未声明的标识符

C++ 错误C2065:&x27;cout';:未声明的标识符,c++,namespaces,visual-studio-2010,std,C++,Namespaces,Visual Studio 2010,Std,我正在处理编程作业中的“驱动程序”部分,我不断遇到这个荒谬的错误: 错误C2065:“cout”:未声明的标识符 我甚至尝试过使用std::cout,但我遇到了另一个错误,即:智能感知:名称空间“std”没有成员“cout”当我声明使用名称空间std时,包括iostream+我甚至尝试使用ostream 我知道这是一个标准的noob问题,但这让我感到困惑,我是一个新手(意思是:我以前编程过…) #包括 使用名称空间std; int main(){ cout在你开始这个程序之前,去掉所有的代码,在

我正在处理编程作业中的“驱动程序”部分,我不断遇到这个荒谬的错误:

错误C2065:“cout”:未声明的标识符

我甚至尝试过使用std::cout,但我遇到了另一个错误,即:智能感知:名称空间“std”没有成员“cout”当我声明使用名称空间std时,包括iostream+我甚至尝试使用ostream

我知道这是一个标准的noob问题,但这让我感到困惑,我是一个新手(意思是:我以前编程过…)

#包括
使用名称空间std;
int main(){

cout在你开始这个程序之前,去掉所有的代码,在main中做一个简单的hello-world。只包括iostream和使用namespace-std;。 一点一点地添加到它,以发现您的问题

cout << "hi" << endl;

cout下面的代码使用gcc为我正确编译和运行。请尝试复制/粘贴此代码,看看它是否有效

#include <iostream>
using namespace std;

int bob (int a) { cout << "hey" << endl; return 0; };

int main () {
    int a = 1;
    bob(a);
    return 0;
}
#包括
使用名称空间std;

如果你所包含的唯一文件是IoSo流传,它仍然表示未定义,那么也许IoSoint不包含它应该做的。你有可能在你的项目中有一个被巧合地命名为“IoSoW”的空文件吗?< /P> < P>你确定它是编译成C++的吗?检查你的文件名(它应该在<代码>结束。CPP < /代码>)。请检查项目设置

你的程序没有任何问题,
cout
位于
namespace std
中。你的VS 2010 Beta 2安装有缺陷,我不认为这只是你的安装

<>我认为VS 2010还没有准备好C++。标准的“hello,Word”程序在beta 1上不起作用。我只是试着创建一个测试win32控制台应用程序,生成的<代码>测试。CPP < /C>文件没有<代码>主()/<代码>函数。< /P>
我对VS 2010有一种非常非常糟糕的感觉。

我有VS2010、Beta 1和Beta 2(一个在我的工作机器上,一个在家里),我使用了大量的
std
但没有问题。试着键入:

std::

看看智能感知是否给了你任何东西。如果它给你常用的东西(<代码>异常中止/代码>,<代码> ABS,<代码> ACOS等),除了<代码> CUT,那是相当令人困惑的。在这种情况下,绝对要查看你的C++头。


除此之外,我还要补充一点,以确保您正在运行一个常规的、空的项目(而不是CLR,在CLR中,Intellisense受到了破坏),并且您实际上至少尝试过构建项目一次。正如我在一篇评论中提到的,VS2010在您添加了
include
后会解析文件;可能是因为有什么东西卡住了解析器,它没有立即“找到”
cout
(在这种情况下,尝试重新启动VS-maybe?)当我用C++代码使用.c文件扩展名时,我也看到类似的事情。除此之外,我必须同意每个人关于Bug安装的情况。如果你尝试用VS的较早版本来编译这个项目,那么它是否有效?VC++Express 2008。它在MSDN上免费。

HR > 它是编译器——我现在使用的是EclipseGalileo,程序运行起来就像一个奇迹



通常存储在C:\Program Files\Microsoft Visual Studio 8\VC\include文件夹中。首先检查它是否仍然存在。然后选择工具+选项、项目和解决方案、VC++目录,在“显示目录”组合框中选择“包含文件”,并双击$(VCInstallDir)

我从一开始就开始了一个MS C++ 2010项目时也遇到了同样的问题——我删除了MS生成的所有头文件,但是使用了:

#include "stdafx.h"
#include <iostream>
using namespace std;

int main() {
   cout << "hey" << endl;
   return 0;
}
#包括“stdafx.h”
#包括
使用名称空间std;
int main(){

如果你使用

#include <iostream.h>
#包括
那你就有问题了

如果你使用

#include <iostream>  
#包括
(通知-无.h)


那么您就不会遇到您提到的问题。

试试看,它会起作用。我在Windows XP、Visual Studio 2010 Express中检查过它

#include "stdafx.h"
#include <iostream>
using namespace std;

void main( ) 
{
   int i = 0;
   cout << "Enter a number: ";
   cin >> i;
}
#包括“stdafx.h”
#包括
使用名称空间std;
空干管()
{
int i=0;
cout>i;
}

如果您启动的项目需要
#include“stdafx.h”
行,请将其放在第一位。

获取代码

#include <iostream>
using namespace std;

在.cpp代码的顶部。然后再次运行它。

编写此代码,它可以完美地工作

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
 cout<<"Hello World!";
  return 0;
}
#包括“stdafx.h”
#包括
使用名称空间std;
int main()
{

Cuth

在VisualStudioC++ 2010中也有同样的问题。它很容易修复。上面的Mead()函数只需替换下面包含的标准行,而在前面包含了磅符号。

# include "stdafx.h"
# include <iostream>
using  namespace std;
#包括“stdafx.h”
#包括
使用名称空间std;

我在安装vs 2010并试图让一个几乎相同的程序运行后遇到了这个错误

我以前在unix风格的盒子上做过普通的C代码,我决定自己来做一点

我尝试的第一个程序是:

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
    cout << "Hello World!";
    return 0;
}
看起来很奇怪。应该是:

int main( int argc, char ** argv )
就我而言,我只是将程序更改为:

#include <iostream>
using namespace std;

int main()
{
     cout << "Hello world from  VS 2010!\n";
     return 0;
}
#包括
使用名称空间std;
int main()
{

cout当您创建项目时,您没有正确设置“使用预编译头”。请在属性->C/C++->预编译头中更改它。

在Visual studio中,使用“stdafx.h”下面的所有头文件管理器。

包含“stdafx.h”的
可以

但是您不能使用
cout
,除非您包含了
使用名称空间std


如果未包含命名空间std,则必须在Visual Studio中编写
std::cout
而不是简单的
cout
,您必须
#包含“stdafx.h”
,并且是cpp文件的第一个包含项。例如:

这些将不起作用

#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;
}
#包括
使用名称空间std;
int main(){

不能只使用
printf

stdafx.h
头文件中包含
stdio.h
int main( int argc, char ** argv )
#include <iostream>
using namespace std;

int main()
{
     cout << "Hello world from  VS 2010!\n";
     return 0;
}
#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;
}
using namespace std;
// Example a
#include <iostream>    
#include "stdafx.h"
// Example b
#include "stdafx.h"
#include <iostream>  
#include "pch.h"
#include <iostream>

using namespace std;

int main() {
    cout << "Enter 2 numbers:" << endl;