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

10th Mar 2019, 2:54 AM
Kishan Yadav
Kishan Yadav - avatar
2 Answers
+ 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 << ....
10th Mar 2019, 5:30 PM
B K
+ 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.
4th Oct 2020, 6:47 AM
Aqsa Anwar Memon
Aqsa Anwar Memon - avatar