Page 1 of 1

Help with C++

Posted: Wed Feb 24, 2010 8:14 pm
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

Re: Help with C++

Posted: Wed Feb 24, 2010 8:17 pm
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.

Re: Help with C++

Posted: Wed Feb 24, 2010 8:22 pm
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.

Re: Help with C++

Posted: Wed Feb 24, 2010 8:45 pm
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.

Re: Help with C++

Posted: Wed Feb 24, 2010 8:51 pm
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

Re: Help with C++

Posted: Wed Feb 24, 2010 8:52 pm
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.

Re: Help with C++

Posted: Wed Feb 24, 2010 8:52 pm
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. ;)

Re: Help with C++

Posted: Wed Feb 24, 2010 8:55 pm
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

Re: Help with C++

Posted: Wed Feb 24, 2010 9:12 pm
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.

Re: Help with C++

Posted: Thu Feb 25, 2010 12:22 pm
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.