Having the following code:
int main(int argc, char* argv[]) {
// program code
std::cout << std::endl << "Press <ENTER> to exit..." << std::endl;
std::getchar();
return 0;
}
When I start this program from Visual Studio it writes:
"Press <ENTER> to exit..."
waits for ENTER key pressed, than writes Visual Studio standard:
"Press any key to continue..."
Therefore, from Visual Studio (Ctrl+F5) I need to press buttons two times, but only one is desired.
How can I workaround this issue (some code that detects start from Visual Studio and allows to “comment” my “key press waiting code”)?
Thanks
You can set up your project settings so that Visual Studio passes a command line argument to your program every time it starts up. So, just make a command line argument which tells it not to pause on exit, and set up Visual Studio to pass that argument.
If you’ve never worked with command line arguments before, they show up in
argc/argvin yourmain.