CHAPTER10-25.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER10-25.cpp
- #include <map>
- #include <iostream>
- #if _MSC_VER > 1020 // if VC++ version is > 4.2
- using namespace std; // std c++ libs implemented in std
- #endif
- void main( )
- {
- map <int, int> m1;
- int i;
- typedef pair <int, int> Int_Pair;
- m1.insert ( Int_Pair ( 1, 1 ) );
- m1.insert ( Int_Pair ( 2, 1 ) );
- m1.insert ( Int_Pair ( 1, 4 ) );
- m1.insert ( Int_Pair ( 2, 1 ) );
- // Keys must be unique in map, so duplicates are ignored
- i = m1.count( 1 );
- cout << "The number of elements in m1 with a sort key of 1 is: "<< i << "." << endl;
- i = m1.count( 2 );
- cout << "The number of elements in m1 with a sort key of 2 is: "<< i << "." << endl;
- i = m1.count( 3 );
- cout << "The number of elements in m1 with a sort key of 3 is: "<< i << "." << endl;
- }