Page 1 of 1

C++ compiling error

Posted: Fri Dec 10, 2010 12:23 pm
by ShiunYean
I've been having problem compiling C++ with Microsoft Visual C++ 2010 Express Edition for a long time now.
Here's an example.

My code(Exactly the same as examples in the book):

Code: Select all

#include <iostream>

using namespace std;

int main()
{
	cout << "Hello, I am your computer talking." << endl;
	return 0;
}
And I get this error:

Code: Select all

1>------ Build started: Project: Hello World!!, Configuration: Debug Win32 ------
1>  Hello World!!.cpp
1>e:\cppprojects\helloworld\hello world!!\hello world!!.cpp(1): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1>          Add directive to 'StdAfx.h' or rebuild precompiled header
1>e:\cppprojects\helloworld\hello world!!\hello world!!.cpp(10): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
But when I use the Visual Studio command prompt to compile it, it works perfectly.
Is it something that is wrong with the software?

Re: C++ compiling error

Posted: Fri Dec 10, 2010 7:10 pm
by Nerrazzuri
add

Code: Select all

 #include "stdafx.h"
on the very top.

Re: C++ compiling error

Posted: Fri Dec 10, 2010 8:02 pm
by ShiunYean
Thx! I keep trying to add it to the 2nd line, but it didn't work.
I even try adding it after using namespace std;

Re: C++ compiling error

Posted: Sat Dec 18, 2010 2:40 am
by happy125
just wondering, how come hello world script require another header file? i thought iostream itself is enough already? and if the complier is vc++ shouldnt it be windows.h?

Re: C++ compiling error

Posted: Sat Dec 18, 2010 9:24 pm
by Nerrazzuri
It is the default header for VC++.

Re: C++ compiling error

Posted: Sun Dec 19, 2010 3:09 pm
by happy125
which means VC++ doesnt include those header files when compling? cause im using GNU GCC complier and hello world just require iostream.

Re: C++ compiling error

Posted: Sun Dec 19, 2010 4:19 pm
by Nerrazzuri
happy125 wrote:which means VC++ doesnt include those header files when compling? cause im using GNU GCC complier and hello world just require iostream.
Thats the precompiler header for VC++

Re: C++ compiling error

Posted: Sun Dec 19, 2010 6:41 pm
by happy125
i think i got it. thanks for ur help. btw just to let u know that ur link for DLL trainer links to the general programming page instead of the thread.

Re: C++ compiling error

Posted: Mon Dec 20, 2010 10:59 pm
by Nerrazzuri
It is not able to quote the whole thread with '[' and ']' so I just link them to general programming.