Namespaces are to avoid naming conflicts. C++ is based on C and C has many problems with function and variable names because sometimes functions from different library clashes. So library developer started to prefix their functions with library names like the following:
foo/foo.h:
void libfoo_foo_foo_h_open(); // the name can be weird then even this one!
C++ introduced namespace to solve this problem in an easy way.
Assume you have two libraries named file and window which handles files and windows respectively and the following code:
#include <file.h>
#include <window.h>
using namespace file;
using namespace window;
void open() {
...
}
file.h:
namespace file {
void open(); // What!
}
window.h:
namespace window {
void open(); // Oh no!
}
The above code will surely and certainly fail to compile.
If you don't like type std:: (only 5 characters) you can always do this: (not a good idea in header files)
using s = std;
If you still want to use using namespace std; in your source file then you are inviting that problem and I have to ask you "What is the PURPOSE of a NAMESPACE?".
std::literals::chrono_literals,Poco::Data:Keywords,Poco::Unitsand stuff that will deal with literals or readability tricks. Whenever it is in header or implementation files. It might be OK in a function scope I guess, but apart from literals and stuff, it is not useful.using [namespace]::[identifier];in the local scope of relatively simple source files. For example, if I have a header frequently using the fully qualified:std::size_ttype, I will typically prepend:using std::size_t;to the implementation. This simplifies reading the code, and only effects the local scope - that is:using std::[identifier];employs the principle of least surprise. There are too many identifiers in thestdnamespace to keep track of. Later C++ revisions may add identifiers that clash with your own!