User forums > Help

the program closes too fast...

<< < (2/2)

takeshimiya:
In those cases is expected to use system("pause")

Or put a getchar() or something.

Zeus:
getchar() didnt do anything...and ive heard that system("PAUSE") is bad programming practice...any other solutions

rickg22:
If you want to redistribute your program you can make a batch file... which would run the program in question and then do the pause.

Also, you might try EXPERIMENTING with getchar(), I think there was a case when the user didn't press any input... i think it returned 0...

again, it might be that the input buffer wasn't empty... argh. I don't really remember. You might like to try some c++ programming (specialized) forums...

Hope that helps :)

sethjackson:
Here is a simple program in C++ that waits until the user presses enter to quit.


--- Code: ---#include <cstdlib>
#include <iostream>

int main()
{
    std::cout << "Hello World!";
    std::cout << std::endl;
    std::cout << "Press Enter to exit.";
    std::cout << std::endl;

    std::cin.get();

    return 0;
}

--- End code ---

This is probably not the most efficient way but it will work on all OS.

Navigation

[0] Message Index

[*] Previous page

Go to full version