3 ms·
> I had failed to understand that I needed to run the program via cmd.exe because of course Hello World exits immediately when it's printed the text. And till
by Sharlin 9y ago
> I had failed to understand that I needed to run the program via cmd.exe because of course Hello World exits immediately when it's printed the text.
And till this day, people writing command-line programs in an IDE like Visual Studio stumble on this fact, and the workaround is still the same: adding an stdin read or something like system("PAUSE") at the end, pausing the execution until the user hits Enter.
- to3m 9y agoBest solution I've found: static void PressEnter(void) { if(IsDebuggerPresent()) { fprintf(stderr,"press enter\n"); getchar(); } } Then from somewhere right near the top of main or whatever: atexit(&PressEnter); You can throw in some isatty calls, or #ifdef _CONSOLE, or if(GetConsoleWindow()), etc., but the above pretty much always does the right thing.
- int_19h 9y agoOr you can flip the switch in the IDE itself to pause on exit.