Help

Discussion in 'C++' started by Gbosa, Apr 27, 2010.

  1. Gbosa

    Gbosa New Member

    Joined:
    Apr 27, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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;
    }
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Moved to C-C++ forum
     
  3. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    Hi !
    Welcome to G4EF :) :welcome:

    Change your code to something like :

    Code:
    #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.
     
  4. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28

    its getchar(); you forgot the ;
     
  5. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    Yeah .. :)

    Thanx virxen, for pointing out !
     
  6. Poonamol

    Poonamol New Member

    Joined:
    Mar 31, 2010
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    0
    Put a breakpoint at return 0 line / getch line.
    U'll see can output.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice