Use Namespaces

Namespaces help organize identifiers used in a program in order to avoid name conflicts. Because the standard library, as implemented with the new header file organization, places names in the std namespace, using these header files requires that you deal with namespaces.

The examples in this book, for simplicity, utilize a using directive to make all the names from the std namespace available:

#include <iostream>
#include <string>
#include <vector>
using namespace std;                // a using-directive

However, the wholesale exporting of all the names in a namespace, whether needed or not, runs counter to the goals of namespaces.

Instead, the recommended approach is to use either using declarations or the scope resolution operator (::) to ...

Get C++ Primer Plus, Fourth 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.