Most things in the various STD libs are namespaced as to not clash with other programs. using namespace
imports everything in a namespace into your current namespace, even for things you didn’t include.
It’s just a shortcut to write less, and is a bad habit taught to beginners. It can cause name collisions for all sorts of things since it imports all of std, not just the headers you include.
Just don’t use it. If you insist, scope your use of using
by putting it inside of functions/methods, and specify specific things to import (i.e. using std::string;
).
Yeah the value copy is necessary to return the old (pre-increment) value with i++. However, your compiler is (usually) smart enough to optimize the copy away if you never use it.
That being said, being explicit is good, so use ++i if you don’t need the old value. Don’t depend on the compiler to maybe do something.