Help with compiling in VC++ Express

Started by
5 comments, last by JonBMN 11 years, 8 months ago
I've been programming in C# for a few years now and I really love it.
Now I will be learning c++ in school.
I'm used to VC# Express so I downloaded VC++ Express (do you have any other suggestions on a IDE?) and bought Starting out with c++ early objects 7e to get comfortable with the language and IDE, but I have already encountered problems. Even the simplest code won't compile, so I ask you if there is some settings or something else I'm missing.

I'm trying to do a simple console application that will output some text.


#include <iostream>

using namespace std;

int main()
{
cout << "Text";

return 0;
}

The error says: "Error 2 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?"

If I do inlcude StdAfx.h I get: "Error 2 error C2065: 'cout' : undeclared identifier"

None of the code in the book compile. Please help.

Another question, how do I activate intellisense in VC++ Express 2010?

EDIT: Removed the code block
Advertisement
The error says: "Error 2 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?"


When creating a C++ project in Visual Studio, select "Create emtpy project" and uncheck "create precompiled headers". Otherwise, go to your project properties (alt+f7), and navigate to C/C++ -> Precompiled headers, and set "Use precompiled headers" to "do not use".

[quote name='Basse85' timestamp='1343752816' post='4964910']The error says: "Error 2 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?"


When creating a C++ project in Visual Studio, select "Create emtpy project" and uncheck "create precompiled headers". Otherwise, go to your project properties (alt+f7), and navigate to C/C++ -> Precompiled headers, and set "Use precompiled headers" to "do not use".
[/quote]

that is correct, OR do as the compiler suggests and just add an #include "StdAfx.h" as your first line.

Stefano Casillo
TWITTER: [twitter]KunosStefano[/twitter]
AssettoCorsa - netKar PRO - Kunos Simulazioni


[quote name='fastcall22' timestamp='1343754108' post='4964914']
[quote name='Basse85' timestamp='1343752816' post='4964910']The error says: "Error 2 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?"


When creating a C++ project in Visual Studio, select "Create emtpy project" and uncheck "create precompiled headers". Otherwise, go to your project properties (alt+f7), and navigate to C/C++ -> Precompiled headers, and set "Use precompiled headers" to "do not use".
[/quote]

that is correct, OR do as the compiler suggests and just add an #include "StdAfx.h" as your first line.
[/quote]

They already tried that, and that is definitely not the right solution even if it did work.
Inellisense should be activated by default, but I also had some problems recently with not showing up. Try to restart your system and try again.
Just for your information, intellisense simply means auto completion. If you write std:: for example it should give you a list of functions and classes within that namespace.
You can also force this by typing Ctrl+J or Ctrl+Space. Just note that the intellisence of c++ is not as advanced as it is in c# and works a little bit differently. In c# when I write 'Con' it will automaticly give me a list beneath where I can select Console, in c++ this is not by default and Im not sure if this can actually be selected.
fastcall22 and vleugel, thank you!

I've been programming in C# for a few years now and I really love it.
Now I will be learning c++ in school.
I'm used to VC# Express so I downloaded VC++ Express (do you have any other suggestions on a IDE?) and bought Starting out with c++ early objects 7e to get comfortable with the language and IDE, but I have already encountered problems. Even the simplest code won't compile, so I ask you if there is some settings or something else I'm missing.

I'm trying to do a simple console application that will output some text.


#include <iostream>

using namespace std;

int main()
{
cout << "Text";

return 0;
}

The error says: "Error 2 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?"

If I do inlcude StdAfx.h I get: "Error 2 error C2065: 'cout' : undeclared identifier"

None of the code in the book compile. Please help.

Another question, how do I activate intellisense in VC++ Express 2010?

EDIT: Removed the code block


it seems you forgot to place endl; at the end of your cout expression..

it should be
#include <iostream>
using namespace std;
int main()
{
cout << "Text" << endl;
return 0;
}

This topic is closed to new replies.

Advertisement