Tuesday, October 29, 2013

Pause Screen or Stop Console Screen for Hello World C++ Programe

One of the very first programs written in C++ is the Hello World program. Simple as it seems, it is often problematic. The problem is that when the program is executed for the first time, either in Dev C++ or Microsoft Visual Express, the console either flashes on for a second or does not appear at all.

The culprit, a missing line of code, system("pause"). With a system pause, your console will stop so you can actually view your code's output on the console screen. The system pause lets you pause the console until you decide to press enter. In fact it will print on the screen, Press Any Key to Continue. You can also use the cin statement to pause your console so you can see what your program calculated or printed.



// my first program in C++

#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";

   
//The console will close quicker than a bat's eye without a system pause

system("pause");
 
 
  return 0;
}

No comments:

Post a Comment