I see people using "std::cout" or "std::cin", and I'm curious if there's any reason to not use "using namespace std;" at the beginning of the program. Does appending "std::" make it run faster or something?
Yeah, you generally should avoid a using statement in a header, because it forces the header's users to also have the using statement. Otherwise it's all up to taste. Because the std:: namespace is huge, I'd much rather perform a using statement than qualify everything. Other namespaces might be a different story (boost for example).
You should also understand why namespaces were added to the language in the first place,
because a "using namespace std;" in a .cpp file defeats the purpose of namespaces in that
.cpp file.
Namespaces were added to avoid global name conflicts. For example, you might be using
two libraries, both of which define a class called "List". If those declarations are not in
a namespace, then you end up with ODR (one definition rule) violations that lead ultimately
either to compile errors or unexpected runtime behavior. By putting the declarations in
separate namespaces and referring to them with their fully qualified name, there is no
ambiguity as to which one you mean.
When you use blanket "using namespace" clauses, you potentially reintroduce those
ambiguities.
Having said all this, unless you are compiling against multiple external libraries or are working
on an extremely large project, you _probably_ won't have any troubles by just writing
"using namespace std;" in your .cpp files.
Ohh, that makes sense. I was just talking about seeing std::cout in the beginner programs on this forum, but it always helps to know the background behind a particular part of anything. Thanks!