std:: vs using namespace std | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

std:: vs using namespace std

I heard that writing "using namespace std" is a bad style. But is it normal to add "std: :" to every endl, sin and cout?

23rd Oct 2016, 7:46 PM
Kristina Drobysh
Kristina Drobysh - avatar
1 Answer
+ 1
Hi, using std:: is considered good style as it makes clear what function, class or instance you mean: the ones in std. If you have functions, classes etc with the same name but in different namespaces you *need* to do it to be unambiguous. Being explicit and portable is exactly why you write namespace specifiers.
23rd Oct 2016, 8:00 PM
Stefan
Stefan - avatar