C++ › Namespaces

What does 'using namespace std;' do and why is it discouraged in headers?

Beginner

Answer

using namespace std; brings all names from std into the current scope so you can omit the std:: prefix. It's discouraged, especially in headers, because it pollutes the global/namespace scope everywhere the header is included, risking name collisions and ambiguities. Prefer explicit std:: or targeted using-declarations in narrow scopes.
using std::cout;   // targeted, safer
// avoid: using namespace std;  in headers
Real-world example A using namespace std in a widely-included header causes a surprising ambiguity with a user 'count' function.

Common follow-ups: Why is it worse in headers? | What is a safer alternative?