Thursday, 12 December 2013

Program to accept message and display a message in the output in C++


// Program to accept message and display a message in the output.


#include<iostream>
#include<conio.h>        //for the purpose of getch()
using namespcae std;   //Explained after this program
int main()
{
     char ch[20];
    
     cout<<"Enter the name : "<<endl //endl- manipulator used instead of \n
     cin>>ch;
     cout<<ch;

    return 0;
}


In this program, we come across
1. namespace std
2. endl

Namespace std
    •Namespaces are used to prevent name conflicts
    •Namespace std is used routinely to cover the standard C++ definitions, declarations, and so on for standard C++ library
    •The using directive is equivalent to using a declaration for each item in a namespace
    •All functions and variables are declared under the namespace “std”.

Endl
   •Input and output can be formatted using manipulators
   •To use manipulators without arguments,
      (e.g., endl, flush, dec, hex, left, right, etc. ) <iostream> must be included
   •Manipulators with arguments
      (e.g., setw(n), setprecision(n), etc. ) require the header <iomanip>

No comments:

Post a Comment