0
What is special feature of using namespace std; . does IT strictly required for C plus plus .please explain
While I pick any code from internet there is a header file mention using namespace STD But in our book of C plus plus programming it is never mention Even my teacher don't know or (don't tell me) Explain me what is this what error will come if I not use that Sorry for bad English
2 ответов
+ 3
For example:
We have two namespases
namespace A
{
void print()
{
std::cout << "namespace A";
}
}
namespace B
{
void print()
{
std::cout << "namespace B";
}
}
The two namespaces A and B have a function with a same name 'print'
if we write this:
using namespace A;
using namespace B;
and we call 'print' function,
the compiler will not know which 'print' to use
so for not make mistakes we use
A::print() or B::print()
When we write using namespace std we can use all functions and classes which are in namespace std whitout write std:: before every function. For example:
using namespace std;
cout << ....
And if we dont write "using namespace std":
std::cout << ....
+ 1
yeah, it's necessary to use "using namespace std" otherwise the compiler won't be able to know that what is cout and cin. If you don't wanna use this statement then you have to use std:: before every court statement. So, it is better to use one statement in the program and feel relax.
#include<iostream>
int main()
{
cout<<"hello world!";
}
try to run this code, you will find an error.