Solution of command line window flashback when visual studio runs C + + program

(By Tan Tan)
First, problem description
The original code looks like this:

#include <iostream>
 
int main()
{
    std::cout << "Hello World!\n";
    return 0;
}

The function is to print Hello World! From a command line window. However, the command line window will flash back as soon as I run it, and I haven’t even had time to read my Hello World!!
Second, solutions
Tried several methods of website, the following several works:
remember the following words are added before the return!!!!!!!!!
1. Add this sentence before return 0:

getchar();

2. Add this sentence before return 0:

system("pause");

3. Add this sentence before return 0:

cin>>name

The principle of these methods is the same, all want the command line window to wait for you to enter a signal before proceeding to execute, you do not enter a signal better stop there. Getchar () and cin> > The name is all about identifying what you’re typing, and the system(” pause “) should be free to enter a single character without identifying what you’re typing. Another way to do this is to write cin.get () before it; Get what you type, not type it and then execute it.


Read More: