"Hello World" ?!?!?!?!

Status
Not open for further replies.

pcrobot

In Runtime
Messages
233
I'm picking C++ back up, after about a year or so, and already I've got a problem...

I type in:
// my first program in C++

#include <iostream.h>

int main ()
{
cout << "Hello World!";
return 0;
}
I compile and run it using Bloodshed's Dev-C++ program, but it just flashes the DOS output for a split second, (so fast I can't see it) then DOS closes! What am I doing wrong?

Thanks!
 
I haven't programmed in C++ for years, but I think you need a system pause or something like that... system("PAUSE"); maybe.
 
your doing nothing wrong dude,

just add a line so when u press retun key(for ex) u exit ur program
 
joseza82 said:
your doing nothing wrong dude,

just add a line so when u press retun key(for ex) u exit ur program
What would that be?

I tried system("PAUSE"); but it didn't work...
 
pcrobot said:
I'm picking C++ back up, after about a year or so, and already I've got a problem...

I type in:

I compile and run it using Bloodshed's Dev-C++ program, but it just flashes the DOS output for a split second, (so fast I can't see it) then DOS closes! What am I doing wrong?

Thanks!
Windows thang. Yer just running the file and it's pulling up the command prompt, running it, and then closing, because there's nothing else to do.

Do this:

Open the command prompt manually. Execute the file from the prompt.

That should show you "Hello World" on the following line, and then it'll just sit there and wait for your next action.

This is the behavior of how things are executed.
 
Just stick with system("PAUSE");

The only reason it didn't work is because you have not included cstdlib

Pop the folloing at the top of your code and system will work:

#include <cstdlib>
 
OK, I type this:

// my first program in C++

#include <iostream.h>
#include <cstdlib>

int main ()
{
cout << "Hello World!";
return 0;
system("PAUSE");
}

And still it doesn't work... :(
 
Status
Not open for further replies.
Back
Top Bottom