Jump to content
  • Advertisement
Sign in to follow this  
Inverse Infinity

Visual Studio C++ Beginner Woes

This topic is 2899 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone! I'm Inverse Infinity, and I'm just beginning to learn game programming. This is my first post here, so play nice, ok? :D

I've just started to work my way through a book called 'Beginning C++ Game Programming' by Michael Dawson, and I've hit a bit of a snag. In the book, the first exercise is to write a program that will output the string "Game Over!" to the command line when executed. The exact code from the book looks like this:

// Game Over
// A First C++ Program

#include <iostream>

int main()
{
std:cout << "Game Over!" << std:endl;
return 0;
}

However, when I take that code exactly, and put it through Visual Studio 2010 Pro, and attempt to build the project, it causes an error and asks if I had forgotten to include "StdAfx.h". Now, I'm not sure why it's doing this, because after I add it below "#include <iostream>", the build log says it's skipped "include <iostream>" and then brings up 4 other errors. Hmmmm... (Here is a cut/paste from the build log)

1>d:\documents and settings\administrator\my documents\visual studio 2010\projects\game_over\game_over\game_over.cpp(5): warning C4627: '#include "iostream"': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>d:\documents and settings\administrator\my documents\visual studio 2010\projects\game_over\game_over\game_over.cpp(10): error C2039: 'cout' : is not a member of 'std'
1>d:\documents and settings\administrator\my documents\visual studio 2010\projects\game_over\game_over\game_over.cpp(10): error C2065: 'cout' : undeclared identifier
1>d:\documents and settings\administrator\my documents\visual studio 2010\projects\game_over\game_over\game_over.cpp(10): error C2039: 'endl' : is not a member of 'std'
1>d:\documents and settings\administrator\my documents\visual studio 2010\projects\game_over\game_over\game_over.cpp(10): error C2065: 'endl' : undeclared identifier
1>
1>Build FAILED.

Sorry it's a bit long. :D

I've had a bit of a think about this, and have played around with the code a bit to see if I can nut it out myself, but I just can't find any way around the errors. So maybe you guys might be able to help. I got to thinking is the 'iostream' header missing from Visual Studio by default? If so, how can I fix it and if not, what might be happening to cause these problems?

Also, do you have any suggestions about good books to learn C++ game programming from? Have you personally used any that you found good?

Thanks in Advance!

Share this post


Link to post
Share on other sites
Advertisement
StdAfx.h is used when using Precompiled Headers (PCH). It looks like you've chosen the wrong type of project when you created it in Visual Studio. Basically you just want an empty console project (make sure that any tick boxes referring to any includes or anything are unticked).

Share this post


Link to post
Share on other sites
Quote:
Original post by AndyEsser
StdAfx.h is used when using Precompiled Headers (PCH). It looks like you've chosen the wrong type of project when you created it in Visual Studio. Basically you just want an empty console project (make sure that any tick boxes referring to any includes or anything are unticked).


Ah, yes, I did have PCH ticked. Thanks for that, I'll give it another whirl and see what happens. :D

Share this post


Link to post
Share on other sites
Quote:
Original post by Jacob Jingle
Shouldn't that be std::cout, std::endl?


Yep, my bad. It was '::' in the code. Good pickup. :D

And after switching PCH off, hey-presto! It works!

Thanks so much guys!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!