+ 1
Can namespace std be replaced??
2 Antworten
+ 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....)
+ 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.