1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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,276
    Likes Received:
    364
    Trophy Points:
    83
    Moved to C-C++ forum
     
  3. SaswatPadhi

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

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    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 New Member

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

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

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

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    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