#include <cstdlib> #include <iostream> #include <map> #include <utility> using namespace std; int main(int argc, char *argv[]) { map<int, int> m; typedef map<int, int>::value_type vt; for(int i=0; i<50; i++) { int val = rand() % 1000; pair<map<int, int>::iterator, bool> ret; //1th insert mathod ret = m.insert(vt(val, i)); if(!ret.second) cout << "insert key: " << val << "failed" << endl; //2th insert mathod val = rand() % 1000; ret = m.insert(make_pair(val, i)); if(!ret.second) cout << "insert key: " << val << "failed" << endl; } map<int, int>::iterator it = m.begin(); for(it; it != m.end(); it++) cout << it->first << " "; cout << endl; system("PAUSE"); return EXIT_SUCCESS; }
时间: 2024-10-07 07:42:02