I've been using Microsoft Visual C++ Express 2008. When I build the following code I get the following error report. I'm confused because I've checked and rechecked that according to the online beginners guide suggested by microsoft this is good code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
use namespace std;
int main()
{
int length = 5;
int width = 7;
int area = length * width;
cout << "The area of this rectangle is ";
cout << area;
return 0;
}
|
1>------ Rebuild All started: Project: Experiment1, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'Experiment1', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>Experiment1.cpp
1>c:\documents and settings\wuzzzintme\my documents\visual studio 2008\projects\experiment1\experiment1\experiment1.cpp(1) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\documents and settings\wuzzzintme\my documents\visual studio 2008\projects\experiment1\experiment1\experiment1.cpp(3) : error C2143: syntax error : missing ';' before 'namespace'
1>c:\documents and settings\wuzzzintme\my documents\visual studio 2008\projects\experiment1\experiment1\experiment1.cpp(3) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\wuzzzintme\my documents\visual studio 2008\projects\experiment1\experiment1\experiment1.cpp(3) : error C2059: syntax error : ';'
1>c:\documents and settings\wuzzzintme\my documents\visual studio 2008\projects\experiment1\experiment1\experiment1.cpp(11) : error C2065: 'cout' : undeclared identifier
1>c:\documents and settings\wuzzzintme\my documents\visual studio 2008\projects\experiment1\experiment1\experiment1.cpp(12) : error C2065: 'cout' : undeclared identifier
1>Build log was saved at "file://c:\Documents and Settings\WuzzzintME\My Documents\Visual Studio 2008\Projects\Experiment1\Experiment1\Debug\BuildLog.htm"
1>Experiment1 - 5 error(s), 1 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
I was guessing that I was using the compiler wrong and went to the command prompt compiler and found the same errors. Is the book wrong to say this is good code or am I missing something that would be needed for the microsoft compiler?