By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

Command Line Disappears (Win 2000 NT)

P: n/a
Just joined and am learning c++, i have got a compiler, i run the
executable, i get the DOS command prompt showing me my program but once
it gets to the "return 0;" part of the code, basically the end, the
prompt disappears, and i miss out on half of my program. A while back
someone told me of a line of code to put in that fixes this problem,
but i forgot it! Could someone tell me?

thank you!

Jul 11 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"poolshark1691" wrote:
Just joined and am learning c++, i have got a compiler, i run the
executable, i get the DOS command prompt showing me my program but once
it gets to the "return 0;" part of the code, basically the end, the
prompt disappears, and i miss out on half of my program. A while back
someone told me of a line of code to put in that fixes this problem,
but i forgot it! Could someone tell me?
I had that problem the first time I started programming on a Windows
computer, back in 1996. There's 3 easy ways around it, though:

1. (The best by far): lauch a command-prompt window BEFORE you run
your program, and run the program from within that window, by
typing its name.
2. (For people hoplessly addicted to icons): Right-click the icon
that launches your program, select "Properties", go to the
"Program" tab, and UN-check the little box that says "close on
exit".
3. (The really stupid way:) put this line of code at the bottom of
main(), just above "return 0;":
system("pause");

--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter)
http://home.pacbell.net/earnur/
Jul 11 '06 #2

P: n/a

"Robbie Hatley" <bo***********@no.spamwrote in message
news:4P*******************@newssvr21.news.prodigy. com...
"poolshark1691" wrote:
>Just joined and am learning c++, i have got a compiler, i run the
executable, i get the DOS command prompt showing me my program but once
it gets to the "return 0;" part of the code, basically the end, the
prompt disappears, and i miss out on half of my program. A while back
someone told me of a line of code to put in that fixes this problem,
but i forgot it! Could someone tell me?

I had that problem the first time I started programming on a Windows
computer, back in 1996. There's 3 easy ways around it, though:

1. (The best by far): lauch a command-prompt window BEFORE you run
your program, and run the program from within that window, by
typing its name.
2. (For people hoplessly addicted to icons): Right-click the icon
that launches your program, select "Properties", go to the
"Program" tab, and UN-check the little box that says "close on
exit".
3. (The really stupid way:) put this line of code at the bottom of
main(), just above "return 0;":
system("pause");
I think #1 and #2 won't help if you're running from an IDE. And #3 depends
on the OS, right? To do this in my console apps, I use cin to a string. It
requires me to type at least one character and then hit Enter, but it works.

-Howard

Jul 11 '06 #3

P: n/a
"poolshark1691" <po***********@gmail.comwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
Just joined and am learning c++, i have got a compiler, i run the
executable, i get the DOS command prompt showing me my program but once
it gets to the "return 0;" part of the code, basically the end, the
prompt disappears, and i miss out on half of my program. A while back
someone told me of a line of code to put in that fixes this problem,
but i forgot it! Could someone tell me?

thank you!
Instead of running the program with F5 use Ctrl-F5 and the output will stay
until you press a key.

Method 1 (OS specific):
system("pause");

Method 2 (works on any system):
#include <string>
#include <iostream>
std::string wait;
std::cin >wait;
Jul 12 '06 #4

P: n/a
Howard <al*****@hotmail.comwrote:
>
"Robbie Hatley" <bo***********@no.spamwrote in message
news:4P*******************@newssvr21.news.prodigy. com...
>"poolshark1691" wrote:
>>Just joined and am learning c++, i have got a compiler, i run the
executable, i get the DOS command prompt showing me my program but once
it gets to the "return 0;" part of the code, basically the end, the
prompt disappears, and i miss out on half of my program. A while back
someone told me of a line of code to put in that fixes this problem,
but i forgot it! Could someone tell me?

I had that problem the first time I started programming on a Windows
computer, back in 1996. There's 3 easy ways around it, though:

1. (The best by far): lauch a command-prompt window BEFORE you run
your program, and run the program from within that window, by
typing its name.
2. (For people hoplessly addicted to icons): Right-click the icon
that launches your program, select "Properties", go to the
"Program" tab, and UN-check the little box that says "close on
exit".
3. (The really stupid way:) put this line of code at the bottom of
main(), just above "return 0;":
system("pause");

I think #1 and #2 won't help if you're running from an IDE. And #3 depends
on the OS, right? To do this in my console apps, I use cin to a string. It
requires me to type at least one character and then hit Enter, but it works.
Instead of

std::string trash;
std::cin >trash;

I prefer

std::string trash;
std::getline(std::cin, trash);

so that I do not have to type an extra character.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Jul 12 '06 #5

P: n/a
Jim Langston <ta*******@rocketmail.comwrote:
Method 2 (works on any system):
#include <string>
#include <iostream>
std::string wait;
std::cin >wait;
As I replied to Howard, I prefer

std::getline(std::cin, wait);

so that I don't have to type an extra character.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Jul 12 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.