Namespaces

Almost everything in a program has a name. When you start using libraries, there is always the chance that one library may have something in it that has the same name as something in another library. If that happens, the compiler can't tell which thing you meant to use. So C++ library programmers wrap their libraries in namespaces to keep their names separate.

Namespaces are a sort of container for names. Each namespace itself has a name that qualifies (is added to) any names in the code it holds. For instance, the namespace for iostream is named std (shorthand for “standard”) and any name from that namespace is automatically qualified with std—as in std::cout.

The statement on line 3 tells the compiler, “If you see a name and you ...

Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.