Thread: Help me!

  1. #1
    Unregistered
    Guest

    Unhappy Help me!

    Help! I just started learning C++ today, but I am having trouble... When I use the sample code that is in the tutorial... Whenever the code finishes what it is doing the program immediately shuts off before I can even read output and stuff... Is there some setting in windows I need to set so it stops doing this?

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    If u r using windows, put this at the end of your code and make sure u add #include <stdlib.h> to the top of ur code

    system("PAUSE");



    if u r in linux, i have no clue cause i don't have linux. i don't think that it will work under linux.

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937

    Also...

    If you are in Microsoft Visual C++, simply hit "execute" (!) instead of "go".
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    Unregistered
    Guest
    Whatever system you use you can do something like this at the very end of your project:

    ///blah blah blah
    char dummy;
    cout << "enter any key to exit" << endl;
    cin >> dummy;
    return 0;
    }

  5. #5
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    When u do ur version though, u also have to hit enter after u input the char. So, it really wouldn't be press any key to exit.

  6. #6
    Unregistered
    Guest
    you could use getche() as well, or anything that will force the system to wait for input before closing and then ignores the input, for that matter. This technique will work irrespective of operating system or compiler and does not require knowledge of assembly or underlying API (if applicable).

  7. #7
    Unregistered
    Guest
    Wow thanks for the help everyone!

Popular pages Recent additions subscribe to a feed