This is a probably an embarasing question as no doubt the answer is blindingly obvious.
I\'ve used Visual Studio for years, but this is the first time I\'ve done any
A somewhat better solution:
atexit([] { system("PAUSE"); });
at the beginning of your program.
Pros:
cin.sync(); cin.ignore();
trick instead of system("pause");
)Cons:
extern "C" int __stdcall IsDebuggerPresent(void);
int main(int argc, char** argv) {
if (IsDebuggerPresent())
atexit([] {system("PAUSE"); });
...
}
add “| pause” in command arguments box under debugging section at project properties.
Go to Setting>Debug>Un-check close on end.
try to call getchar()
right before main()
returns.
Here is a way for C/C++:
#include <stdlib.h>
#ifdef _WIN32
#define WINPAUSE system("pause")
#endif
Put this at the top of your program, and IF it is on a Windows system (#ifdef _WIN32
), then it will create a macro called WINPAUSE
. Whenever you want your program to pause, call WINPAUSE;
and it will pause the program, using the DOS command. For other systems like Unix/Linux, the console should not quit on program exit anyway.
Currently there is no way to do this with apps running in WSL2. However there are two work-arounds:
The debug window retains the contents of the WSL shell window that closed.
The window remains open if your application returns a non-zero return code, so you could return non-zero in debug builds for example.