Help

Gbosa's Avatar, Join Date: Apr 2010
Newbie Member
Hello , i am new to programming. How can i stop my executed code as below from disappearing .It appears my compiler is too fast.It compiles ok but the black output plan appears and disappears immediately when executed

#include <iostream>
using namespace std;
int main()
{ cout << "Hello World!";
return 0;
}
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Moved to C-C++ forum
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Hi !
Welcome to G4EF

Change your code to something like :

Code: CPP
#include <iostream>

using namespace std;

int main()
{
    cout << "Hello World!";
    getchar()
    return 0;
}
BTW, any C++ compiler would behave the same way as yours, it's not about a fast compiler.
Your code basically prints "Hello World!" and then exits, so you fail to see the output.
If you instruct it to wait for a key-stroke before exiting (getchar ()), you can have your output on screen, till you press a key.
virxen's Avatar, Join Date: Nov 2009
Pro contributor
Quote:
Originally Posted by SaswatPadhi View Post
Hi !
Welcome to G4EF

Change your code to something like :

Code: CPP
#include <iostream>

using namespace std;

int main()
{
cout << "Hello World!";
getchar()
return 0;
}


BTW, any C++ compiler would behave the same way as yours, it's not about a fast compiler.
Your code basically prints "Hello World!" and then exits, so you fail to see the output.
If you instruct it to wait for a key-stroke before exiting (getchar ()), you can have your output on screen, till you press a key.

its getchar(); you forgot the ;
SaswatPadhi like this
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Yeah ..

Thanx virxen, for pointing out !
Poonamol's Avatar, Join Date: Mar 2010
Go4Expert Member
Put a breakpoint at return 0 line / getch line.
U'll see can output.