No. No usingnamespace std;. Bad habit. Do not learn.
If you use cout only once, then write std::cout.
If you use cout multiple times in main(), then write:
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
int main() {
using std::cout; // function scope
// other code
cout << "Hello ";
// other code
cout << "Dolly!\n";
// other code
return 0;
}
If you use cout in many functions, then:
1 2 3 4
#include <iostream>
using std::cout; // file scope
Only in the most narrow scope and only the necessary symbols.
Ah, thank you. A lot better of a solution. I've sort of fallen into that bad habit from just being taught wrong from the start, and then forgetting it was a bad habit. I learned coding with the mindset that "std:: is only for super professional code. Just use the namespace std!" and never bothered to correct it.
And I agree. Which compiler did you buy, if you don't mind me asking?
Things can get pretty messed up.
The first two answers do a pretty good job of explaining how things can go south, and most of the time without you even realizing!
http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice