Console window shuts down instantly
| mac173 (4) | |||
| I am just beginning to try to teach myself programming. I have the Borland Turbo C++ compiler. My first "Hello World" program seemed to run, but the console window that opened closed the instant it opened, so I cannot see the output. I cannot find anything in the help files. I ran the test program to see if the compiler is compliant to ANSI C++, but the same thing happens. This is the code I ran. #include <iostream> using namespace std; template <class T> bool ansisupported (T x) { return true; } int main() { if (ansisupported(0)) cout << "ANSI OK"; return 0; How do I get the console window to stay open till I tell it to close? | |||
| Zhuge (56) | |||
| From what I've seen, most people use system("pause") which will wait for a key press. The reason it closes immediately is because it runs the commands then returns, ending your program. Windows then closes the command window because it is finished. | |||
| mac173 (4) | |||
| Ok, that makes sense. May I ask, where do I insert the system("pause") line in that code? I would guess just before the return, but trying that gave me errors. I really am a rank beginner, can you specify the exact code I need to insert? | |||
| mac173 (4) | |||
| OK, I got it. Thanks for your help. #include <iostream> using namespace std; int main () { cout << "Hello World!"; system ("pause"); return 0; } that ran, and gave me the line "Enter any key to continue..." Just what I needed. THANKS! | |||
| Duoas (1387) | |||
| Arrgh. http://www.cplusplus.com/forum/beginner/1865/#msg6775 | |||
This topic is archived - New replies not allowed.
