Can namespace std be replaced?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can namespace std be replaced??

4th Aug 2016, 10:56 AM
Prabhat Chandra Dwivedi
Prabhat Chandra Dwivedi - avatar
2 Answers
+ 3
Instead of replaced, I would said that it's not mandatory... but if you decide not to use it you will need to call each standard method and property explicitly using the name scope resolution operator :: (std::cout, std::cin....)
4th Aug 2016, 11:12 AM
Nelson Urbina
Nelson Urbina - avatar
+ 2
In larger programs, using namespace std is considered bad programming practice as it could potentially cause conflicts if you're working with different libaries with functions of the same name. The best way to combat this would be to simple put std:: before any keyword of the standard libary (like Nelson said). Alternatively, you could put using std::cout; at the top of your program (replace cout with any standard libary keyword), and that will save the hastle of constantly writing std::. The first method that Nelson mentioned is considered the best practice.
4th Aug 2016, 2:26 PM
Cohen Creber
Cohen Creber - avatar