Wednesday 1 August 2012

How to display something on command prompt in C++



Program that displays your name, street address, city and state on 

three separate lines on the screen.



#include<iostream>

#include<conio.h>

using namespace std;

int main()
{
              cout << "Name: Your Name" << endl << endl;
              cout << "Street: Your Address" << endl << endl;
              cout << "City: Your City \t State: Your State" << endl << endl;     

              //__ Note - \t is used for Space __
      
              getch();
      
              return 0;
      
              /*__ Return 0 tells the compiler that program has

              executed successfully without any error ____*/
}


cout statements are used to display something on command prompt. endl is used to take the cursor to the next line. getch() is defined in header file <conio.h>

Note - In C++ we used to avoid writing .h with the header files but as conio.h is a header file of C thats why .h is written with <conio>

No comments:

Post a Comment