DOS app question

  • Thread starter Michael Huntwork
  • Start date
M

Michael Huntwork

Hello,

I am new to C++ and am taking my first class and in my programs I
would like to add a non-required feature.

I would like for my app to not close immediately after completion in
Windows when starting it via the ol' double click.

I know that if I start it from a DOS prompt everything will work out
just fine but I and several others would like to "improve" our
projects.

Any suggestions?

Thanks,

Mike
 
S

Sumit Rajan

Michael Huntwork wrote:

I am new to C++ and am taking my first class and in my programs I
would like to add a non-required feature.

I would like for my app to not close immediately after completion in
Windows when starting it via the ol' double click.

I know that if I start it from a DOS prompt everything will work out
just fine but I and several others would like to "improve" our
projects.

Add "system("pause");" at the point you require your program to display a
"Press any key to continue ... " sort of prompt.

HTH,
Sumit.
 
S

Sumit Rajan

Sumit said:
Michael Huntwork wrote:



Add "system("pause");" at the point you require your program to display a
"Press any key to continue ... " sort of prompt.


Remember that this is not a very portable way of doing this since "pause" is
a DOS command which displays something to the effect of "Press any key to
continue ... ". Using pause will not work on Linux, etc.

Sumit.
 
A

Attila Feher

Michael said:
Hello,

I am new to C++ and am taking my first class and in my programs I
would like to add a non-required feature.

I would like for my app to not close immediately after completion in
Windows when starting it via the ol' double click.

I know that if I start it from a DOS prompt everything will work out
just fine but I and several others would like to "improve" our
projects.

Any suggestions?

OFF-TOPIC

Read in a string at the end of your code. Or (since it seems to be for
Windows only) include <stdlib.h> (not stdlib, which would be C++, MS
compilers had problems with putting everything to std namespace) and call
system("pause"); at the end of your program. (This is a non-portable little
hack!)

Please note, that your question has nothing to do with the C++ language!
Before you post here again, please read this:
http://www.slack.net/~shiva/welcome.txt
 
M

Mike Wahler

Michael Huntwork said:
Hello,

I am new to C++ and am taking my first class and in my programs I
would like to add a non-required feature.

I would like for my app to not close immediately after completion in
Windows when starting it via the ol' double click.

I know that if I start it from a DOS prompt everything will work out
just fine but I and several others would like to "improve" our
projects.

Any suggestions?

#include <iostream>

int main()
{

/* your code */

std::cout << "Press return to continue";
std::cin.get();
return 0;
}

-Mike
 
M

Mike Wahler

Sumit Rajan said:
Michael Huntwork wrote:



Add "system("pause");" at the point you require your program to display a
"Press any key to continue ... " sort of prompt.

This will only work for platforms which have such a 'pause'
command, and that it does what the OP asks. I.e. it's a non-
portable solution. See my post this thread for a portable
solution.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,364
Latest member
Stevanida

Latest Threads

Top