Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

I am having trouble. I am currently learning c++?

I am a newbie at c++ programming and just downloaded the Microsoft Visual C++ program to practice with my c++. However, after i am done with the most basic code: such as

#include <iostream>

using namespace std;

int main()

{

cout << "Hello World";

}

I copied this straight out from the website and after i complied it, and run it another window (Black Window) showed up with the word "HELLO WORLD" but it wont stayed open? it literally closed in 2 seconds after i pressed run (f5). Any ideas why its like this? I learned c++ a while back and when I run the program i wrote, the *black window .exe. stayed on. Please help me out, i am currently learning it. thank you!

Update:

perhaps, i should add that i am using the Microsoft Visual Basic C++ express 2010

Update 2:

Thank you guys for the help!

5 Answers

Relevance
  • Favorite Answer

    Since you don't pause at any time, the code finishes executing and then terminates.

    There are many ways to get around this; you can input a dummy line:

      string dummy;

      getline(cin, dummy);

    Older C++ books might recommend you use something line getch() from the <conio.h> library; this is not recommended, however, as <conio.h> is non-standard.

    A commonly-used way to force the program to wait is to use a system call, i.e.:

      system("pause");

    I don't know if this will work in VC++, as I don't use it myself, but some IDEs will allow you to "View Output" or "View Console" via some menu option; you can do this if you can find it.

    Edit -- it appears that you can use Ctrl+F5 to run the program and have it pause on termination; see source.

  • 10 years ago

    Try adding this after the cout statement:

    cin.get();

    That tells the cin stream to wait for the next input token, holding the window open until you press Enter.

  • 10 years ago

    I don't know c++ but when I was playing with python, this happened because the program is done after it prints "Hello World". So if you put something after that (waiting for an input or whatever) it should stay on screen.

  • ?
    Lv 4
    5 years ago

    i grow to be having that concern with a distinctive chord and a extra performed participant instructed me "stand your palms up". concern-free for somebody with relatively long palms to declare yet nonetheless solid suggestion. attempt curling your palms and arching your hand somewhat, and practice the chord arpeggio type, playing each and each word in series fairly of strumming all of them jointly. Your hand and palms gets extra suitable with everyday practice and your fingertips gets sore, yet whilst your wrist hurts you're in all probability overcompensating.

  • How do you think about the answers? You can sign in to vote the answer.
  • 10 years ago

    use getch(); at the end of the program ..

    include header file conio.h

Still have questions? Get your answers by asking now.