LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   using namespace std; (https://www.linuxquestions.org/questions/programming-9/using-namespace-std%3B-626202/)

JMJ_coder 03-06-2008 12:47 PM

using namespace std;
 
Hello,

I wanted to find out how many C/C++ developers actually use this in their programming.

ta0kira 03-06-2008 01:25 PM

It has limited usefulness for learning C++, but it ultimately promotes vague code and dumps common names into the global namespace, possibly introducing bugs. I think in non-trivial programs it's a lazy shortcut that provides minimal additional convenience at best. You can place using... between headers to keep headers after it from dumping into the global, but that makes it more confusing.

There is one exception, though. Some STL libraries (though not necessarily compliant) place standard C functions in namespace std. Putting using... in the local scope of a function can be useful to promote portability to those compilers and it has no effect outside of that scope.
ta0kira

osor 03-06-2008 01:41 PM

I do not put “using namespace std;” in my code. If I need to dump anything from a different namespace into mine (if I use it many times), I will explicitly import only those and nothing else. E.g.,
Code:

using std::vector;
using std::fstream;



All times are GMT -5. The time now is 06:01 PM.