Why we use namespace std

My question is that why we use "using namespace std;" in Visual studio for "cout" while in Turbo C++, DEv it is not required.
Long ago C++ did not have namespaces. Everything was in global namespace as in C. As different libraries developed, some of them became de-facto standard, other just widely used and problem of name clashing became more urgent. Then new standard came with conceptions of namespaces. Now every single lib can use its own namespace and do not conflict with others. All standard language library was moved into namespace std and it was prohibited by standard for users to add anything to it and discouraged "hijacking" other namespaces too. To make overloads of standard functions for you classes lay in class namespace and make Koenig lookup magic possible, using declaration was added. For those who want a quick code mockup and likes to wonder why his distance function does not compude distance correctly, using directive was added.

BAsically: Turbo and DevC++ are extemely outdated and shouldn't be used.
If you want future employment in programming stop using using namespace std; right now
Last edited on
> it was prohibited by standard for users to add anything to it (namespace std)
1
2
3
4
namespace std{
   bool really();
   bool are_you_sure();
}
Standard wrote:
17.6.4.2.1 Namespace std [namespace.std]
1 The behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to a namespace within namespace std unless otherwise specified. A program may add a template specialization for any standard library template to namespace std only if the declaration depends on a user-defined type and the specialization meets the standard library requirements for the original template and is not explicitly prohibited.181
Last edited on
Topic archived. No new replies allowed.