#include <iostream>
usingnamespace std;
int main() {
int cin;
// cin >> cin; //Whoops!
std::cin >> cin; //Here you still need the prefix, so why bother confusing yourself
...
}
I usually use "option 2" in files without a main function and when not in global scope, as to be more careful.
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
namespace my_ns {
using std::ostream;
class T {
...
};
ostream& operator<<(ostream &out, const T &t) {
...
}
}
Ideally, no one should ever name a variable or class with the same name as something in the standard library. With that said, you still shouldn't count on other people to not make mistakes.
Usually, yes - except when dealing with the std namespace.
Fully qualifying names in the std namespace has little practical advantages, but is a tremendous waste of time.