Help with C++

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Zunedude123
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 4
Joined: Sun Feb 21, 2010 5:52 pm

Help with C++

Post by Zunedude123 »

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
jacob.krustchinsky
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 34
Joined: Tue Feb 23, 2010 10:18 pm

Re: Help with C++

Post by jacob.krustchinsky »

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.
User avatar
hurstshifter
ES Beta Backer
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++

Post by hurstshifter »

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
Zunedude123
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 4
Joined: Sun Feb 21, 2010 5:52 pm

Re: Help with C++

Post by Zunedude123 »

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.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Help with C++

Post by eatcomics »

Zunedude123 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.
First of all code tags plz, thnx... second this will work

Code: Select all

#include <iostream>
using namespace std;

int main(){
     cout << "hello world, this will work for rlz!\n";
     return 0;
}
your main problems are the capital I in include #include not #Include they are different and same goes for int main not int Main... the using namespace std just makes it so you don't need std::cout and std::cin you can just type cout or cin
Last edited by eatcomics on Wed Feb 24, 2010 8:55 pm, edited 3 times in total.
Image
User avatar
Falco Girgis
Elysian Shadows Team
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++

Post by Falco Girgis »

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.
User avatar
Falco Girgis
Elysian Shadows Team
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++

Post by Falco Girgis »

eatcomics wrote:

Code: Select all

#include <iostream>
using namespace std;

int main(){
     cout << "hello world, this will work for rlz!\n";
     return 0;
}
No, that won't work in Visual Studio with precompiled headers turned on. ;)
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Help with C++

Post by eatcomics »

GyroVorbis wrote:
eatcomics wrote:

Code: Select all

#include <iostream>
using namespace std;

int main(){
     cout << "hello world, this will work for rlz!\n";
     return 0;
}
No, that won't work in Visual Studio with precompiled headers turned on. ;)
oh, hm... never had that on...

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
Image
Zunedude123
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 4
Joined: Sun Feb 21, 2010 5:52 pm

Re: Help with C++

Post by Zunedude123 »

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.
User avatar
Falco Girgis
Elysian Shadows Team
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++

Post by Falco Girgis »

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.
Yeah, embedded manifests would have nothing to do with that. You should probably hang out here more often (we know what we're doing). ;)

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.
Post Reply