c++ – Do I need to write two colons before std?


Some authors use two colons :: before the std , for example:

auto v = ::std::vector<int>(42);
::std::cout << "Hello, World!" << ::std::endl;

I know that this indicates the use of identifiers from the global osprey, but is the std identifier used in any other way (except for programmer jokes)?

Wouldn't that be an over-insurance, akin to, for example, checking that false is false rather than being overridden by #define (by adding #undef false )?


Every time you can explain to the driver that the car is being repaired in a car repair shop, and not in a hospital, but it is better not to clog the airwaves once again.

If someone does not understand that std::vector is an STL container, then he will not understand exactly what ::std::vector<::std::string> means, and how insurance it looks a little funny.

Personally, in addition to efficiency and everything else, I pay attention to the readability of what I write (this does not mean that I write perfectly …), i.e. I try not to litter the page with unnecessary characters, and the broadcast with unnecessary words …

It's a matter of taste..

If I write a code where only vector and cout appear from namespace std, then using namespace std; will only unnecessarily litter the global space, but using std::vector; using std::cout; will be the very thing …

Scroll to Top