Why doesn't this code compile and run in Visual Studio 2010?

I am trying to get Visual Studio 2010 to create a simple old ANSI compiler without Microsoft extensions.

I started with an empty project template, since in 2010 there seems to be no simple ANSI project template.

Then I installed

Properties β†’ Configuration Properties β†’ C / C ++ β†’ Language β†’ Disable Extensions = Yes (/ Za)

Here is my code:

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

Here are the errors:

 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 

How can I get this, the simplest of C ++ code to compile?

+7
source share
2 answers

The error disappears if wchar_t defined as a native type .

+5
source

If I copy your code to test.cpp file and then issue the command

 cl /Za /EHsc test.cpp 

it compiles easily without any warnings or errors when installing Visual C ++ Express 2010./EHsc is necessary for the exception handling to work properly, and I don’t understand why it is not standard.

Is it any different than what you do?

0
source

All Articles