I have read the "Console Closing Down" thread (http://www.cplusplus.com/forum/beginner/1988/) completely, but there doesn't seem to be an answer I'm looking for. I know all of the ways not to keep the console open, but I can't find the "recommended" way of keeping the console open.
It's only for small personal projects, so I know I could use things like system("PAUSE"), etc. but I want to learn to do it the right way.
But remember what is probably the second most important thing from that pinned thread: the solution became necessary only because the original poster's IDE failed to keep the console open like most other IDE's.
i was playing around with _getche(), i found that when i press only Enter, the return value was 13 decimal.
if the Enter key sends a value of 13, you can use this as the delimiter for cin.ignore().
i don't have time to try it, i'm really sorry.
hope that was useful.
Enter sends the newline character into the buffer, and '\n' has an ASCII code of 10.
Don't depend on a nonstandard function like _getche(). In the past, I used getch() to find the ASCII values returned by the arrow keys, but the values were different depending on where in my program the getch() was called.
Edit: cin.ignore(number_to_ignore, delimiter);
The delimiter is what character the function should stop at even if it has not read in the "number(of characters)_to_ignore".
Edit 2:
Rechard3, the value you got was probably for the carriage return, which might work fine. I think only Windows and Macs use '\r' (13).
You mean so it should look like this?: std::cin.ignore( '\n', std::numeric_limits<std::streamsize>::max());
With it like that,^^ It doesn't close immediately, but instead I must press enter 10 times to close. Or press enter 5 times, if I'm "submitting" an integer with it.
I'm getting different results, depending on which .exe I run. Should I be running the "main.exe" in my programs folder, or should I run the "program_name_here".exe in "\bin\Debug"?
Ima767god:
"CTRL + F5" does nothing for me, are you using Code::Blocks?