How to make a window stay open after running C ++ code?

Possible duplicate:
How to immediately close a C ++ console application?

I'm trying to see my results, what should I do with my code so that I can see if I did the right thing?

#include <iostream> using namespace std; int main() { cout << "C++" << endl; cout << "The sum of 11 + 12 = " << 30/2 << endl; return 0; } 
+6
source share
4 answers

I think that you mean that your DOS terminal closes as soon as your program ends.

A common solution is to call cin , scanf or getch at the end of your program immediately before your return 0 . This makes the program wait for any user to enter before exiting.

It is best to compile your program and then run it from the DOS prompt. Just run the DOS prompt, cd in the directory your program is in and run it from there.

+5
source

Use getchar() at the end of the code or just run the executable from the console.

+4
source

Another way for windows is: system ("pause");

+2
source
 #include <iostream> using namespace std ; int main(void) { std::cout<<" \nPress any key to continue\n"; std::cin.ignore(); return 0; } 
+1
source

Source: https://habr.com/ru/post/907091/


All Articles