In C++ the using
statement is not related to including the functionality of that namespace (or type). Instead, it allows you to use the namespace in the statement without a namespace prefix in the rest of the current scope (or compilation unit if you have the statement in global scope) after the using
statement.
So you could either write
#include <string>
std::string my_string;
or
#include <string>
using namespace std;
string my_string;
As others have mentioned - the first version is more recommended than the second, because there's usually a reason that things are in their own namespace (such as the std
namespace here). If you have a blanket using
statement you may get unexpected name clashes or other issues. This is especially true if you do it in a header file, which you should never do unless you know exactly what the results will be and where.