Automatic Closing?

H

HHH

Can someone tell me why does my c++ program always close straight away when
i open it. For example, i had made a build version of my first program
"Hello World", and when i tried it, it opened and closed. Is there a code i
have to right or something?
 
G

gabriel

If your program is a console program it's supposed to do that when you run
in debug mode. In this case, insert a delay or "press any key"
functionality at the end.

You can run the program in execute mode (ie, CTRL-F5), then the compiler
will do a "press any key" thing for you.

Also, you might have a better time in comp.os.ms-windows.programmer.win32
for product-specific questions.
 
T

Thomas Matthews

HHH said:
Can someone tell me why does my c++ program always close straight away when
i open it. For example, i had made a build version of my first program
"Hello World", and when i tried it, it opened and closed. Is there a code i
have to right or something?

Unless your program prompts the user for input (hint!!!)
or delays, the operating system is allowed to terminate it
after its execution.

In some windowing operating systems, a new window is opened
for an application. As soon as the application is finished,
the window closes. In these scenarios, most programmers
employ a "press any key" prompt for the user.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 

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

Staff online

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top