Computing.Net > Forums > Programming > C++ Hello world Problem!

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

C++ Hello world Problem!

Reply to Message Icon

Original Message
Name: thecody
Date: July 30, 2007 at 18:59:21 Pacific
Subject: C++ Hello world Problem!
OS: Windows Xp
CPU/Ram: Pentium D
Model/Manufacturer: HP
Comment:

Ok first off i'm new to this site, so if this is the wrong place for this question please tell me where it should be, or answer the question if possible. OK i'm just beginning my study of C++ i am starting out with the traditional hello world exercise. Now i'm using dev C++ and my book said to put in
#include <iostream.h>

int main()
{
cout << "Hello World!\n";
return 0;
}
That didn't work even though i copied and pasted right from the book and after much hours of research for some reason it had to be:
#include <iostream>

int main()
{
std::cout <<"Hello World!" << std::endl;
return 0;
}
anyway that doesn't bring up errors like the last one did, but when i execute it I see the black dos screen thing flash really quickly, so fast i can't even see if it says Hello world or not. I thought it was spose to stay up so i could read it. What's going wrong?????



Report Offensive Message For Removal


Response Number 1
Name: Razor2.3
Date: July 30, 2007 at 19:26:17 Pacific
Reply: (edit)

If it compiled, it worked.

If you really want it to stay up, add this line just after the cout line:
system("PAUSE");


Report Offensive Follow Up For Removal

Response Number 2
Name: thecody
Date: July 30, 2007 at 19:34:39 Pacific
Reply: (edit)

Awesome that works now, thanks. Why didn't our exercise book tell us about that. Did they expect us to read it in like 1/10th of a second??? also why did my book's command not work, and the one i had to find on the internet work, does it have to do with my complier, or what?


Report Offensive Follow Up For Removal

Response Number 3
Name: Razor2.3
Date: July 30, 2007 at 20:04:54 Pacific
Reply: (edit)

why did my book's command not work
They don't have your version of your C++ library. There's usually small changes between libraries, but it's more-or-less the same. For reference, #include <iostream> is the more correct version.

Why didn't our exercise book tell us about that.
Two guesses: They expected you to run the compiled version from the Command Prompt, or their IDE automatically keeps the window open for you. Visual Studio automatically does it, for example.


Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: July 31, 2007 at 03:22:27 Pacific
Reply: (edit)

Like #3 the book assunes you're at the prompt.

I think it's standard to precede include[s] with #. Dunno how the book spaced that out. Wrong book?


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 5
Name: tonysathre
Date: July 31, 2007 at 14:23:56 Pacific
Reply: (edit)

The C language uses #include <iostream.h>
C++ uses #include <iostream>

"Computer security." — Oxymoron


Report Offensive Follow Up For Removal


Response Number 6
Name: Mechanix2Go
Date: July 31, 2007 at 14:27:46 Pacific
Reply: (edit)

Hio tony,

Good ol Borland TCPP 1 uses #include <iostream.h>.


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 7
Name: Jason628
Date: August 1, 2007 at 08:38:55 Pacific
Reply: (edit)

If you don't want to use the std:cout stuff

put the following under the includes.

using namespace std;

If you don't want to use the system(pause)

open up the command prompt and run your code from
there.



Report Offensive Follow Up For Removal






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you own an iPhone?

Yes
No, but soon
No


View Results

Poll Finishes In 7 Days.
Discuss in The Lounge
Poll History




Data Recovery Software