We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
A lot of things you use often (like cout/cin/ and even the string data type) in C++ are actually part of the standard library and live in the std namespace.
Meaning- when you include a "standard library file" (say "iostream"), you actually tell your compiler to include code from the "iostream" code file.
The functions/classes/data types and etc' are all defined inside this code within the std namespace.
If you use cout without "using namespace std;"- when you would try to compile your code- your compiler would tell you there is not "cout".
That's because cout is included somewhere in the code your compiler processes- but its visibilty (aka "scope") is limited.
When you don't use "using..." you would have to call cout- std::cout, string- std::string and so on.
Variable Sized Arrays
You are viewing a single comment's thread. Return to all comments →
A lot of things you use often (like cout/cin/ and even the string data type) in C++ are actually part of the standard library and live in the std namespace.
Meaning- when you include a "standard library file" (say "iostream"), you actually tell your compiler to include code from the "iostream" code file. The functions/classes/data types and etc' are all defined inside this code within the std namespace.
If you use cout without "using namespace std;"- when you would try to compile your code- your compiler would tell you there is not "cout". That's because cout is included somewhere in the code your compiler processes- but its visibilty (aka "scope") is limited.
When you don't use "using..." you would have to call cout- std::cout, string- std::string and so on.
There is nothing wrong with simplifying things in this code with putting the "using" statement- but in bigger projects- it's bad practice: http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
It also helps when learning- so you would understand what comes from the standard library, and what header you even got to include in which file.