I'm learning C++ and I'm using Visual C++ Express and while running this
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
the cmd window closes so fast, I can't see Hello World is there anyway to prevent this?
I'm learning C++ and I'm using Visual C++ Express and while running this
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
the cmd window closes so fast, I can't see Hello World is there anyway to prevent this?
Put a getc() right before the return. The program will close only if you press any key.
Yes the common solution is to add a statement that reads input from the keyboard. This call blocks execution till some key is pressed. You can do it with statements like
printf("Hit \"Enter\" to continue\n");
fflush(stdin); /* Remove anything that is currently in the standard input */
getchar(); /* Wait for the user to hit the enter key */
If you press Control + F5, you won't be attached with a debugger - however, it'll stay open with a "Press any key to continue" style message.