Ending a program

I do not want my end programs to end as "Press any key to continue"
Is there another way for them to end like "Press 0 to exit"
or "Press c to continue" ?
Keyboard input is buffered and sent to the program only after the enter key has been pressed. Read this page:
http://web.archive.org/web/20070621025921/http://krtkg1.rug.ac.be/~colle/C/get_char_without_enter.html
unfortunately am using a windows platform and the unix cords i suspect must be slightly different because they are not running.
Here's an example:

1
2
3
4
5
6
7
8
...
do
{
    //code
    char input;
    std::cout << "Press 0 to continue...";
    std::cin >> input;
} while (input == '0');

Is that what you want?
Let me be more clear on this, I am using c-free as my IDE, normally when using it, after running my code with the DOS console, it tells me to "press any key to continue" but people say that that form of ending a program is some what rude,

Is there another way to make the compiler bring what i want and not that statement "Press any key to continue" ?
It sounds like it's added by the IDE.
I don't know the specific IDE you use but I could image that the IDE calls a batch like this:

Without IDE:
console - execute MyProgram.exe
console - execute HelperScript.bat

HelperScript.bat contains
MyProgram.exe
pause

(pause prints this message to the screen; simply try it on the console)

So what you need to do is to search your IDE for the option to suppress the "Press any key to continue" appendix.

Alternatively you can run your program from the console itself.


If you don't use something like Browni3141 provided you, your code will run and exit so fast the user won't be able to see the results. Your IDE added that pause in there for YOUR convenience during debugging only. You will have to add the equivalent code in your actual application that others will use. In any case, how is forcing them to press a particular key better than pressing any key???
Topic archived. No new replies allowed.