c++ 为什么这段代码不能在Visual Studio 2010中编译和运行?

u0sqgete  于 2023-04-01  发布在  其他
关注(0)|答案(2)|浏览(164)

我正试图让Visual Studio 2010设置为进行普通的老式ANSI编译,而不需要任何形式的Microsoft扩展。
我从一个空的项目模板开始,因为在2010年似乎不再有普通的ANSI项目模板了。
然后我设置

属性-〉配置属性-〉C/C++ -〉语言-〉禁用扩展=是(/Za)

下面是我的代码:

#include <iostream>

int main( int argc, const char* argv[] )
{
  std::cout << "Hello World!";
  return 0;
}

以下是错误:

1>------ Build started: Project: ansi_test, Configuration: Release Win32 ------
1>Build started 4/27/2011 4:20:00 PM.
1>InitializeBuildStatus:
1>  Touching "Release\ansi_test.unsuccessfulbuild".
1>ClCompile:
1>  Main.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(636): error C3861: 'width': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(636): error C3861: 'width': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(639): error C3861: 'flags': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(643): error C2227: left of '->sputc' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(643): error C2780: 'void std::fill(_FwdIt,_FwdIt,const _Ty &)' : expects 3 arguments - 0 provided
1>          C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(2712) : see declaration of 'std::fill'
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(643): error C3861: 'rdbuf': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(648): error C2227: left of '->sputc' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(648): error C3861: 'rdbuf': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(654): error C2227: left of '->sputc' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(654): error C2780: 'void std::fill(_FwdIt,_FwdIt,const _Ty &)' : expects 3 arguments - 0 provided
1>          C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(2712) : see declaration of 'std::fill'
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(654): error C3861: 'rdbuf': identifier not found
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(659): error C3861: 'width': identifier not found
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.63

我如何得到这个,最基本的C++代码编译干净?

uxhixvfz

uxhixvfz2#

如果我将代码复制到文件test.cpp中,然后发出命令

cl /Za /EHsc test.cpp

然后它编译干净,没有任何警告或错误,我安装的Visual c++ express 2010. /EHsc是必要的,以便正确处理异常,我真的不明白为什么它不是默认值。
这和你正在做的有什么不同吗?

相关问题