A Separate using Declaration Is Required for Each Name

Each using declaration introduces a single namespace member. This behavior lets us be specific about which names we’re using. As an example, we’ll rewrite the program from § 1.2 (p. 6) with using declarations for the library names it uses:

#include <iostream>// using declarations for names from the standard libraryusing std::cin;using std::cout; using std::endl;int main(){    cout << "Enter two numbers:" << endl;    int v1, v2;    cin >> v1 >> v2;    cout << "The sum of " << v1 << " and " << v2         << " is " << v1 + v2 << endl;    return 0;}

The using declarations for cin, cout, and endl mean that we can use those names without the std:: prefix. Recall that C++ programs are free-form, ...

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