What does namespace “std” contain?
The built-in C++ library routines are kept in the standard namespace. That includes stuff like cout, cin string, vector, etc. because these tools are used so commonly, its popular to add using “namespace std” at the top of your source code.
Question:
can we make a program without using “namespace std”?
Sol:
Yes, we can make a program without “using namespace std”. but in such a case we have to prfix
cout, cin,endl etc by “std”.
As in below given program.
#include <iostream>
int main()
{
std::cout<<“Hello World”<<std::endl;
int a=10,b=20;
std::cout<<“a = “<<a<<std::endl;
std::cout<<“b = “<<b<<std::endl;
std::cout<<“Enter any no “;
std::cin>>a;
std::cout<<“a = “<<a<<std::endl;
return 0;
}
So that you won’t have to type the std:: prefix constantly.
#include <iostream> int main() { std::cout<<"Hello World"<<std::endl; int a=10,b=20; std::cout<<"a = "<<a<<std::endl; std::cout<<"b = "<<b<<std::endl; // Square of a no std::cout<<"Enter any no "; std::cin>>a; b=a*a; std::cout<<"Number = "<<a<<std::endl; std::cout<<"Square = "<<b<<std::endl; return 0; }
/* Output */ Hello World a = 10 b = 20 Enter any no 5 Number = 5 Square = 25