October 2011
Beginner to intermediate
1200 pages
35h 33m
English
using Directive in Multifunction ProgramsNotice that Listing 2.5 places a using directive in each of the two functions:
using namespace std;
This is because each function uses cout and thus needs access to the cout definition from the std namespace.
There’s another way to make the std namespace available to both functions in Listing 2.5, and that’s to place the directive outside and above both functions:
// ourfunc1.cpp -- repositioning the using directive#include <iostream>using namespace std; // affects all function definitions in this filevoid simon(int);int main(){ simon(3); cout << "Pick an integer: "; int count; cin >> count; simon(count); cout << "Done!" << endl; return 0;}void simon(int n){ cout << ...
Read now
Unlock full access