- 1 year ago
How to prevent (C++) a console window from closing after clicking the close window X
Comment
1 / 1
To prevent a console window from closing immediately after clicking the close window button (X), you can add a system("pause") statement at the end of your C++ program. This will keep the console window open until the user presses any key.
Here's an example:
cpp#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
// Prevent the console window from closing immediately
system("pause");
return 0;
}
After running this program, the console window will stay open until you press any key. This allows you to view the output and any error messages before the window closes.