Console window shuts down instantly

May 11, 2008 at 1:46am
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?
Last edited on May 11, 2008 at 1:47am
May 11, 2008 at 1:57am
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.
May 11, 2008 at 2:06am
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?
May 11, 2008 at 2:53am
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!
May 11, 2008 at 10:27pm
Topic archived. No new replies allowed.