views:

112

answers:

6
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
} 

This code works, but it run then close windows immediately. Need a fix :)

+1  A: 

You can go to Start->Run, type cmd, cd to the project binary directory, then enter your executable name.

Matthew Flaschen
+2  A: 

add this getch() or getchar() before return and the consolw window will stay till you enter something

Raghuram
getch() not works, it said : getch was not declared in this score;but i can use cin.get(); -> Why?
Snoob
`getch` is not a standard C++ function.
Matthew Flaschen
A: 

You could declare a breakpoint at return 0; and run in debug.

ETroll
+1  A: 

Enable the 'Run in Terminal' Qt Creator project setting.

Rob
+1  A: 

I don't know how QT Creators works but you could try.

Add:

char x;
cin>>x;

You'll have to type a letter and press enter to exit.

Or

#include<widows.h>
....
....
system("pause");
return 0;
}

OR

 #include<stdlib.h>
  ....
  ....
  cin.get();
  return 0;
  }
Cristy
system() is declared in stdlib.h
GameZelda
No, try an example using #include<windows.h> and you'll see it works :)
Cristy
A: 

If you are just interested in viewing the output, it is shown in application output section of Qt Creator

Arun