// File: MapInt2String.cpp // Basic map example. Subscript is key. Note use of members first & second // Very good for sparse arrays #include #include #include #include using namespace std; int main() { map Employees; // 1) Assignment using array index notation Employees[5234] = "Mike C."; Employees[3374] = "Charlie M."; Employees[1923] = "David D."; Employees[7582] = "John A."; Employees[5328] = "Peter Q."; cout << "Employees[3374]=" << Employees[3374] << endl << endl; // Will this crash? cout << "Employees[3354]=" << Employees[3354] << endl << endl; cout << "Map size: " << Employees.size() << endl; for( map::iterator ii=Employees.begin(); ii!=Employees.end(); ++ii) { cout << (*ii).first << ": " << (*ii).second << endl; } }