Help with C++
Moderator: Coders of Rage
-
- Chaos Rift Newbie
- Posts: 4
- Joined: Sun Feb 21, 2010 5:52 pm
Help with C++
OK, im new here so bare with me. I dont know if this is the right place to post this but I went out and bought "Sams Teach Yourself C++ in One Hour a Day" and I can't even make a "Hello World." It's not that I'm having trouble writing whats in the book, I just can't get it to compile. Nothing involving "std::cout" has worked right on three machines. I went to Microsoft's site and got the express version of C++. Could that be the problem? Also, when I use "#Include <iostream>", it keeps wanting me to use "#Include <stdafx.h>". Could someone please help me with this? Thank you
-
- Chaos Rift Newbie
- Posts: 34
- Joined: Tue Feb 23, 2010 10:18 pm
Re: Help with C++
Include stdafx.h , Im not entirely sure but that's the header that your application calls to when it used the std::. If you at all like me and hate pre-pending every command with std:: just put using namespace std; under you pre-processor directives and you can start writing just plain cout and cin etc.
- hurstshifter
- ES Beta Backer
- Posts: 713
- Joined: Mon Jun 08, 2009 8:33 pm
- Favorite Gaming Platforms: SNES
- Programming Language of Choice: C/++
- Location: Boston, MA
- Contact:
Re: Help with C++
Pasting the code would have been helpful here. In your post you said you #Include <iostream> is this exactly how you included it? C++ is case sensitive my man, #include and #Include are not the same thing. This may have just been how you typed it in the post though, just show us the code.
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
http://www.thenerdnight.com
-
- Chaos Rift Newbie
- Posts: 4
- Joined: Sun Feb 21, 2010 5:52 pm
Re: Help with C++
The book wants me to type for the Hello World,
"#Include <iostream>
int Main()
{
std::cout << "Hello World! \n";
return 0;
}"
The compiler wants,
"#Include <stdafx.h>
int Main()
{
std::cout << "Hello World! \n";
return 0;
}"
Sorry for not posting this earlier, I'm new at both C++ and these forums. The only other experience I have had was a few games in Blitz 3D and 2D, which I got down pretty well.
"#Include <iostream>
int Main()
{
std::cout << "Hello World! \n";
return 0;
}"
The compiler wants,
"#Include <stdafx.h>
int Main()
{
std::cout << "Hello World! \n";
return 0;
}"
Sorry for not posting this earlier, I'm new at both C++ and these forums. The only other experience I have had was a few games in Blitz 3D and 2D, which I got down pretty well.
Re: Help with C++
First of all code tags plz, thnx... second this will workZunedude123 wrote:The book wants me to type for the Hello World,
"#Include <iostream>
int Main()
{
std::cout << "Hello World! \n";
return 0;
}"
The compiler wants,
"#Include <stdafx.h>
int Main()
{
std::cout << "Hello World! \n";
return 0;
}"
Sorry for not posting this earlier, I'm new at both C++ and these forums. The only other experience I have had was a few games in Blitz 3D and 2D, which I got down pretty well.
Code: Select all
#include <iostream>
using namespace std;
int main(){
cout << "hello world, this will work for rlz!\n";
return 0;
}
Last edited by eatcomics on Wed Feb 24, 2010 8:55 pm, edited 3 times in total.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Help with C++
Oh, I knew exactly what the problem was the second you said #include <stadfx.h>
This may or may not make sense to you, because you're a complete beginner. stadfx.h is a Microsoft precompiled header file. Visual Studio allows you to precompile header or .h files (just like your iostream.h) to reduce compile time.
On the left, in your "solution explorer" right click your project. Go down to properties, and a dialog box should pop up. Find C/++ under "Configuration Properties" then go to "Precompiled Headers" under that.
Now where it says "Create/Use Precompiled Headers" change it to no, and you should be great.
This may or may not make sense to you, because you're a complete beginner. stadfx.h is a Microsoft precompiled header file. Visual Studio allows you to precompile header or .h files (just like your iostream.h) to reduce compile time.
On the left, in your "solution explorer" right click your project. Go down to properties, and a dialog box should pop up. Find C/++ under "Configuration Properties" then go to "Precompiled Headers" under that.
Now where it says "Create/Use Precompiled Headers" change it to no, and you should be great.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Help with C++
No, that won't work in Visual Studio with precompiled headers turned on.eatcomics wrote:Code: Select all
#include <iostream> using namespace std; int main(){ cout << "hello world, this will work for rlz!\n"; return 0; }
Re: Help with C++
oh, hm... never had that on...GyroVorbis wrote:No, that won't work in Visual Studio with precompiled headers turned on.eatcomics wrote:Code: Select all
#include <iostream> using namespace std; int main(){ cout << "hello world, this will work for rlz!\n"; return 0; }
edit: I just realized that the first lines of code I have put on this site in a loooong time... I really need to get some stuff done and come show it off xD
-
- Chaos Rift Newbie
- Posts: 4
- Joined: Sun Feb 21, 2010 5:52 pm
Re: Help with C++
Thanks, the code you posted worked after i turned off the precompiled headers. I have been struggling with that for a while now. I followed another post on a different website that said to turn off embedded manifests.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Help with C++
Yeah, embedded manifests would have nothing to do with that. You should probably hang out here more often (we know what we're doing).Zunedude123 wrote:Thanks, the code you posted worked after i turned off the precompiled headers. I have been struggling with that for a while now. I followed another post on a different website that said to turn off embedded manifests.
The problem with the precompiled header bullshit is that it's something just Microsoft wants to do, and every C++ book wants to teach standard C++. So you get all of these newbies who have never heard of a precompiled header who are trying to compile with Visual Studio and freak out.