Visual c++ VisualStudio2010中的cout

Visual c++ VisualStudio2010中的cout,visual-c++,Visual C++,当我试图编译以下代码时 #include <iostream> using namespace std; #include "stdafx.h" // This was included by Visual Studio int _tmain(int argc, _TCHAR* argv[]) // The name _tmain was generated by Visual Studio { int a = 1; cout << a &l

当我试图编译以下代码时

#include <iostream>

using namespace std;

#include "stdafx.h"  // This was included by Visual Studio 


int _tmain(int argc, _TCHAR* argv[])  // The name _tmain was generated by Visual Studio
{
    int a = 1;
    cout << a << "\n";
    return 0;
}
#包括
使用名称空间std;
#include“stdafx.h”//这是VisualStudio包含的
int _tmain(int argc,_TCHAR*argv[])//名称_tmain是由Visual Studio生成的
{
INTA=1;

cout将iostream include和std名称空间声明放在stdafx.h include之后。然后程序将编译并运行


至于原因,我猜是预编译头(默认启用)依赖于#include指令的精确顺序。将iostream放在第一位意味着stdafx的PCH不再与编译器当时已知的声明的实际顺序匹配。

将iostream include和std命名空间声明放在stdafx.h include之后。然后,程序将编译并运行

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

int _tmain(int argc, _TCHAR* argv[])
{
    int a=10;
    cout << a << "\n";
    cin>>a;
    return 0;
}
至于原因,我猜测预编译头(默认情况下启用)依赖于#include指令的精确序列。将iostream放在第一位意味着stdafx的PCH不再与编译器当时已知的声明的实际序列匹配。

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

int _tmain(int argc, _TCHAR* argv[])
{
    int a=10;
    cout << a << "\n";
    cin>>a;
    return 0;
}
#包括 使用名称空间std; int _tmain(int argc,_TCHAR*argv[] { INTA=10; 库塔; 返回0; }
砰的一声,亲爱的!我写了同样的代码,但只是更改了前三行的顺序。它在控制台上给出的结果没有任何错误或警告。请检查它。

#包括“stdafx.h”
#包括
使用名称空间std;
int _tmain(int argc,_TCHAR*argv[]
{
INTA=10;
库塔;
返回0;
}

砰的一声,亲爱的!我写了同样的代码,但只是更改了前三行的顺序。它在控制台上给出的结果没有任何错误或警告。请检查它。

谢谢。首先,放入#include“stdafx.h”修复了这个问题。还有一个问题。有没有办法让输出显示在一个Visual Basic子窗口中(如eclipse中)而不是在命令提示符窗口中?最后,你如何让程序运行?我所能看到的是,在右弹出菜单中有一个“运行到光标”选项。必须有一种简单的方式来表示“运行”。你创建了一个命令行项目,所以它在命令提示符窗口中运行。我不知道你所说的“Visual Basic子窗口”是什么意思。若要运行该程序,只需按F5或Ctrl+F5键即可--请参阅Visual Studio中的“调试”菜单。谢谢。首先,将#include“stdafx.h”放入修复了该问题。另一个问题。是否有方法使输出显示在其中一个Visual Basic子窗口中(如在eclipse中)而不是在命令提示符窗口中?最后,你如何让程序运行?我所能看到的是,在右弹出菜单中有一个“运行到光标”选项。必须有一种简单的方式来表示“运行”。你创建了一个命令行项目,所以它在命令提示符窗口中运行。我不知道你所说的“Visual Basic子窗口”是什么意思。要运行该程序,只需按F5或Ctrl+F5即可--请参阅Visual Studio中的“调试”菜单。