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

Using namespace std vs std::

I been reading some different books and some use using namespace std and others use std:: . Can someone explain the difference? Also to my understanding i think that syntaxes with std:: in front of it would lose that portion of it if i declare using namespace std. For example std::cout is the same as typing cout and declaring namespace in the beginning where the std:: portion is gone. Is my hypothesis about this correct? Thanks.

19th Jan 2019, 9:56 PM
Noobly
5 Answers
+ 4
Yes, declaring namespace std to be used and then using cout or anything that would usually have std:: in front of it would be the same as using it with std:: in front of it. However, using namespace std is often recognized as a bad practice, as it could cause namespace collisions.
20th Jan 2019, 12:26 AM
Dread
Dread - avatar
+ 3
Yes, absolutely.
20th Jan 2019, 12:28 AM
Dread
Dread - avatar
+ 3
No problem.
20th Jan 2019, 12:30 AM
Dread
Dread - avatar
+ 1
So i should just practice using std:: for good measure?
20th Jan 2019, 12:27 AM
Noobly
+ 1
Thank you :)
20th Jan 2019, 12:30 AM
Noobly