Page 1 of 1

dev-cpp premature closing

Posted: Mon Nov 22, 2010 11:40 am
by PinPoint
ive started learning c++ and came across this problem which i got over:)

using a c++ tutorial doing exactly as said didnt let you see the results in dev-cpp, the window flashed then closed right away.

original(window closing code)

Code: Select all

#include <iostream.h>

int main()
{
     cout << "Hello world\n";
          return 0;
}
this code just made the exe flash after it being compiled and linked. but i found out how to fix it.
use

Code: Select all

#include <cstdio> and getchar()
in the source as shown here...

Code: Select all

#include <cstdio>
#include <iostream.h>

int main()
{
     cout << "Hello world\n";
          getchar();
          return 0;
}
now the window will stay open untill you close it.

for anyone who has the same problem while learning


NOTE: I know that <iostream.h> is outdated and is just <iostream> now but still works with dev-cpp and this is what the tutorial is saying so im going with what it is saying for now.

Re: dev-cpp premature closing

Posted: Mon Nov 22, 2010 6:20 pm
by Sethioz
im using mingw compiler, one that Luigi suggested. never used any of this
however if you have problems, ask Luigi :) he knows C inside out.

Re: dev-cpp premature closing

Posted: Thu Dec 16, 2010 3:26 pm
by wolfguardiann
this problem is cuz u didnt used the

Code: Select all

system("pause");
delete this

Code: Select all

return = 0 
return 0
cuz if sucess it will close , so , dont use that , :)