Console app closes after execution

J

James

I'm totally new to C++ and when I try to execute the simple program I have
written, it closes the console application as soon as it has finished
excuting. This obviously means I cannot see the contents of the console
window.

I'm developing it using Visual C++ 2003, using the console application
template.
 
C

Chris Gordon-Smith

James said:
I'm totally new to C++ and when I try to execute the simple program I have
written, it closes the console application as soon as it has finished
excuting. This obviously means I cannot see the contents of the console
window.

I'm developing it using Visual C++ 2003, using the console application
template.

Have you tried starting the application from a console that you have already
opened?
 
J

James

Chris Gordon-Smith said:
Have you tried starting the application from a console that you have
already
opened?

So simple. Can't believe I didn't think of it myself.

Thank you.
 
J

jalkadir

911!
NO!
This is is the way you do it, please take my advice...
int main(){
std::cout << "I want to see this message" << std::endl;
std::cin.get(); // pause until I press enter...
return 0;
}

The std::cin.get() is what you want to use.
This the true C++ way to handle your problem.


Have fun James!!
 
?

=?iso-8859-1?Q?Ali_=C7ehreli?=

This is is the way you do it, please take my advice...
int main(){
std::cout << "I want to see this message" << std::endl;
std::cin.get(); // pause until I press enter...

If every program waited for a character from its standard input before
exiting, not much could be achieved in today's systems.
return 0;
}

The std::cin.get() is what you want to use.
This the true C++ way to handle your problem.

Taking a character from the standard input has nothing to do with the OP's
_program_; that is not a requirement of the program. The program does its
job and exits. No problem there...

The OP's problem is about not being able to see the output of the program.
That problem can be solved in a number of ways, one of which is to start it
in an environment with some history buffer.

Ali
 
M

Maett

James said:
I'm totally new to C++ and when I try to execute the simple program I have
written, it closes the console application as soon as it has finished
excuting. This obviously means I cannot see the contents of the console
window.

I'm developing it using Visual C++ 2003, using the console application
template.

If you start the program out of the IDE, press "Ctrl-F5" instead of "F5"
to start. Then the console remains open with the message
"Press any key to continue"
at the end.

Maett
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top