Visual Studio IDE Solution of No Window Display or Window Flash When Writing Program

  • 2021-10-27 07:00:25
  • OfStack

When writing programs with Visual Studio IDE, the window is not displayed, or Window 1 flashes away. When encountering this problem, it is not your code that is wrong, but the setting problem of IDE itself, so you don't have to worry about where your code is wrong.

For example, I wrote one such program:


#include "iostream"
using namespace std;

int main(int argc, char *argv[])
{
 cout << "hello world!" << endl;

 return 0;
}

Here are three solutions:

1. Add a pause statement

Before the return statement of the main function, add


system("pause");

Note: If you write a program in C language, you need to add it at the beginning of the program


#include "stdlib.h"

That is to say, it includes the header file stdlib. h, which contains the function system ("pause"). If it does not include this header file, system ("pause") cannot be used.

With the pause statement, the source code becomes:


//#include "stdlib.h"
// If C The language program adds the above statement 
#include "iostream"
using namespace std;

int main(int argc, char *argv[])
{
 cout << "hello world!" << endl;

 // Add a pause statement 
 system("pause");
 return 0;
}

Run the program again, and the output window will run to system ("pause") in the code; Pause when, until you press any key, will not continue to execute the program.

2. Create a new Windows console application

Click on the VS interface in the following order

Documents- > New- > Project

Locate the Windows Console Application in the New Project window, click it, and then press OK

At this time, the window after the written code runs will not flash away.

3. Modify the linker

After writing the code, click on the project in turn- > Project name property

In the pop-up dialog box, click Configure Properties- > Linker- > System, select the console (/SUBSYSTEM: CONSOLE) in the subsystem on the right and click OK.

This can solve the problem that Window 1 flashes away.

Visual Studio IDE program to choose one of the above three methods can solve the problem of no display window or window 1 flash away.

For more exciting content, you can click "Visual Studio 2017 Development and Use Tutorial", and for the installation tutorial of visual studio, you can click "Visual Studio Installation and Use Manual" to learn. I hope you like it.


Related articles: