Sunday 8 June 2014

namespace



NAMESPACE
To read from the standard input we use cin and similarly we use cout to display to the standard output . We need to include namespace std in order to use cin and cout otherwise we need to use scope resolution operator (::) .
Example:--

std::cout<<”ENTER YOUR NAME”<<endl;
std::cin>>name;

std::cout says that we want to use cout in our program and the scope of it is the same as the scope of our program , moreover we want to include it from std namespace ; similarly std::cin says that we want to use cin in our program which is given in the std namespace.

·        Use of using declaration
Example:--

using namespace std;

now we do not need to access cin and cout via name of namespace and the scope resolution operator . We can now directly use cin and cout.

Example:--

cout<<”ENTER YOUR NAME”<<endl;
cin>>name;

No comments:

Post a Comment