ID:276868
May 12 2006, 3:08 pm
|
|
I started learning C++ some months ago and I had this same problem but never got around to asking it. When I made my "Hello World" program and ran it, the command prompt window comes up and closes quickly. I'm sure that it wasn't a runtime because it compiled flawlessly without a warning either. What I'm wondering is, how would I get the screen to stay up long enough for me to even see the displayed message..I was using the Bloodshed Dev C++ compielr by the way..
|
May 12 2006, 3:16 pm
|
|
That is the way windows does it's prompts, unless you manually run cmd and run your program from there.
|
In response to Scoobert
|
|
Hmm, okay. I thought it would be similar to java's command prompt programs..Those close when you press a button after your proccess are done..
|
In response to Mecha Destroyer JD
|
|
You could always have it cin << something randomly for no reason. I used to know a way to make it wait for a command from the user, but I don't remember how to do it, sorry.
|
just put
system("pause");
at the end of main, right before the final closing bracket. I think that's platform-dependent, though, so only use that if you're fiddling around in C++. ~Kujila |
In response to Polantaris
|
|
Yep I knew that would stop it, was jus wondering how to do it without having to do that. Thanks guys. :D
|
In response to Mecha Destroyer JD
|
|
system("PAUSE");
You would be better of using this: cout << "Press enter to continue..."; |
In response to Smoko
|
|
The only problem with that is that you have to press enter specifically. With Windows' pause command you can press any key (I generally whack the spacebar). So on Windows, doing system("pause"); is nicer. Obviously if you want any measure of cross-platform support you can't use it though.
You could always combine both approaches, if you want to get really fancy: #ifdef WIN32 |