Hi,
I prefer not to use 'using namespace std' for a complete .cpp file.
This results from the fact that I some time ago had to port some real old code (mixed C/C++, no STL, not written by me) into our application. Unfortunateley there in some files a 'list' (not STL) was typedef'd, in other places variable names like 'string' were used.
This lead to lot of compiler errors (and caused lot of effort to solve them) since our application even used 'using namespace std' in lot .cpp files.
Therefor my preference is to write 'std::' where I need if it's not too exhaustive - otherwise (seldom) I use 'using namespace std' within a function or a class, but never in global scope.
But, of course this is just a opinion/habit.
ZOPPO
Main Topics
Browse All Topics





by: Infinity08Posted on 2009-08-12 at 05:59:23ID: 25078215
I'll start off with my own view.
I never use the using directive 'using namespace std;' for the simple reason that you cannot guarantee that it won't cause problems. Of course that means that you have to either use using declarations (genre 'using std::cout;') or use the explicit namespace qualifier std:: everywhere, but the extra type work is a small price to pay to avoid certain hard to track down bugs.
Personally, I don't even use using declarations, and always specify the std:: namespace qualifier explicitly wherever needed, simply because it makes explicitly clear that I really want the symbol from the std namespace and not from another namespace.
If you're not convinced of the potential pitfalls of adding 'using namespace std;' in your code, take a look at the below sample code. I'm sure we can agree that this is not an exotic example. Try taking out the 'using namespace std;' line to see the difference.
Select allOpen in new window