+ 3

Is it bad to write "using namespace std" and if so why?

I have heard that it is not a good practice to write "using namespace std" at the beginning of your program and that it is better to write directly: std::cout or std::cin Why is this?

12th Feb 2019, 10:40 PM
Marie
Marie - avatar
5 Answers
+ 5
Take a look at Ace's thread and his own response in it. It should give you a good idea on why the practice isn't too healthy, especially for beginners who don't know what they are doing. https://www.sololearn.com/Discuss/294730/?ref=app
13th Feb 2019, 6:21 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
The main reason people say to not include using namespace std is in case of updates. Say namespace foo got an update with cout in it, the program would get confused over if you meant foo::cout or std::cout, creating errors. It is also just good practice incase if you want to learn something like HTML where you cannot say using <p>
12th Feb 2019, 11:54 PM
Cheese Burger Joe
Cheese Burger Joe - avatar
+ 1
Thank you!
13th Feb 2019, 12:13 AM
Marie
Marie - avatar
0
Why then does the sololearn course for c++ use it? Shouldn't it be logical for beginners not to get into bad habits?
13th Feb 2019, 8:54 PM
Marie
Marie - avatar
0
Marie if coding is your first language, like me, it is difficult enough to remember what to code in general, of course after a while when people like me and you do research on this topic usually we start using std:: . So as putting std before everything is better, it just makes it easier to memorize what to code, even if in the future you get an error.
14th Feb 2019, 12:33 AM
Cheese Burger Joe
Cheese Burger Joe - avatar