Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Help (http://www.go4expert.com/forums/help-t21926/)

Gbosa 28Apr2010 03:52

Help
 
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 28Apr2010 08:59

Re: Help
 
Moved to C-C++ forum

SaswatPadhi 28Apr2010 09:02

Re: Help
 
Hi !
Welcome to G4EF :) :welcome:

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 28Apr2010 22:47

Re: Help
 
Quote:

Originally Posted by SaswatPadhi (Post 67527)
Hi !
Welcome to G4EF :) :welcome:

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 29Apr2010 09:20

Re: Help
 
Yeah .. :)

Thanx virxen, for pointing out !

Poonamol 29Apr2010 11:46

Re: Help
 
Put a breakpoint at return 0 line / getch line.
U'll see can output.


All times are GMT +5.5. The time now is 02:35.