August 2012
Intermediate to advanced
976 pages
30h 17m
English
using Declaration Is Required for Each NameEach 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, ...
Read now
Unlock full access