VC + + If the operation is F5, said to debug the way to run, if the breakpoint can be stopped, you can also step into debugging, monitoring variables. Exit immediately at the end of the program.
If you are running on CTRL+F5, it means running in a separate way, even if you encounter a breakpoint, it will not stop. But the end of the program will show a "press any key to continue" dongdong, so you have enough time to observe the results of the operation.
In other compiled environments under Windows, to achieve a similar effect, add a sentence at the end of the program:
System ("pause");
This system function is included in the header file Stdlib.h (c + + is cstdlib).
Method 1: Use CTRL + F5 to run your program.
Method 2: Add GetChar () or Getch () at the end of the program, and don't forget the header file conio.h.
Method 3: Insert System ("pause") in your code to see
Let's explain why it flashed:
When you run the program in VC + +, VC + + will call the line command mode (ie Command.com program), open your program. The line command mode is automatically exited when the program has finished executing. So you're too late to see the output of your program.
The easiest solution to solve this problem is to return 0 at the end of your code, plus
GetChar ();
Getch () does not seem to be part of ANSI C
This statement will make your program do the last thing: read a character from the input buffer (the input stream stdin). In other words, after your other program is finished, you have to knock back to end all the programs.
However, note that when the program is almost over, if there is already a character in your input buffer, the C language will read a character directly from the buffer and then end the program. Instead of waiting for your input.
Like what:
#include <stdio.h>
int main (void)
{
Putchar (GetChar ());
Your program has only one sentence, the role is to enter a character, and then the computer will output it
GetChar ()//This is your statement to prevent a flash.
return 0;
}
The program will still flash through at the end. The reason is that when the first GetChar () expression executes, it returns the first character you entered, followed by the character (including the carriage return character '/n ') left in the buffer. To solve such problems, we have to improvise, there is no unified solution. In this example, you can do this:
#include <stdio.h>
int main (void)
{
Putchar (GetChar ());
Your program has only one sentence, the role is to enter a character, and then the computer will output it
while (GetChar ()!= '/n ')
continue;//This loop will clear the contents of the input buffer until the line breaks.
GetChar ()//This is your statement to prevent a flash.
return 0;
}
A more complex solution is to not execute in Visual C + +. Your husband into the executable file, then open Line command mode (run->cmd), and then run your program there, it will not automatically quit.
Sorry, just tried a moment, ctrl+f5 indeed can, Parason said very right.
I would not like to, but write for a long time, do not send a pity, moreover, from my writing these, you can understand some of the original rational things. Also, I write a generic approach that can be used even if it is not Visual C + +.