It works fine, no major problems here. But, I've heard a lot that using the declaration "using namespace std" is usually a bad thing. My question is, how much does that really matter, and if it does matter, is prefixing string declarations with "std::" absolutely the only way to make things work?

It seems like, in general, it's a matter of preference, but if there's a significant reason not to do things this way, please bring it to my attention.

EDIT: Just to be clear, I don't mean this as a general "how do you use the standard namespace" question, that I understand. My question is specifically, are there any special considerations for it that I might not know about when it's being used solely in a file of defined constants?

Re: Alternative to using namespace std

Posted 19 April 2012 - 08:44 AM

The problem with using the "using namespace std;" clause it that you bring the entire std namespace into the global space. There are functions in the std namespace that have the same name as a function in the global namespace. Another option is the "using std::cout;" type statements. This will only bring in that particular member into the global namespace. But this can still lead to name clashes, much less often, but it is still possible. By scoping every function, class with the scope resolution operator:: (std::cout) you will avoid these name clashes.

In my opinion the "using namespace std;" method is usually adequate for small self-contained programs but as the program grows larger you will have more problems. Also I believe that it's use defeats the purpose of namespaces and should generally be avoided.

The second method "using std::string" also should be used sparingly in my opinion.

I myself prefer to scope each standard function using the scope operator::. If I do use either of the above methods I try to keep their use a local as possible. Remember you can use these statements inside a function or a single of block of code. I normally will never use anything but the scope operator:: inside an include file, or any file that will be included in another file (template inclusions). By keeping the using declarations as local as possible you will have fewer problems.

While I agree with limiting scope, if it's the only namespace going on I find this the most practical. It lets me honestly declare the prototypes that might ultimately find their why unto a header without killing myself.