Paul CyberCitizen
Paul CyberCitizen

Reputation: 309

"namespace std {}" before "using namespace std;"

I have seen the syntax below in many places where STL classes are used without explicitly qualifying them with std::. What is the advantage of the initial namespace std {}? Why not just put using namespace std;?

namespace std {}
using namespace std;

Upvotes: 13

Views: 324

Answers (1)

Emil Laine
Emil Laine

Reputation: 42828

namespace std {} simply declares the namespace so that the compiler knows about it and doing using namespace std; won't cause an error.

Later in the code stuff from std:: can be #included and they can be automatically referred to without the std:: prefix.

Upvotes: 10

Related Questions