c++ map
#include<iostream>
#include <vector>
#include<map>
using std::vector;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::pair;
using std::map;
typedef pair<int, string> Author;
int playPair() {
?Author a1(1, "david");
?cout << a1.first << "? " << a1.second << endl;
?return 0;
}
void playMap() {
?typedef map<int, string> address;
?Author a1(2, "david");
?Author a2(3, "ccde");
?address mapAddress;
?
?//add element
?mapAddress.insert(a1);
?mapAddress.insert(a2);
?mapAddress.insert(address::value_type(4, "df43234"));
?
?//use iterator
?map<int, string>::iterator iter;
?
?//get element by key
?iter = mapAddress.find(2);
?cout << iter->first << " the first key of 2" << endl;
?//遍历map
?for (iter = mapAddress.begin(); iter != mapAddress.end();
???iter.operator ++()) {
??cout << "| " << iter->first << " | " << iter->second << endl;
?}
?
?//delete element
?iter = mapAddress.find(2);
?mapAddress.erase(iter);
?cout << "after erase" << endl;
?
?for (iter = mapAddress.begin(); iter != mapAddress.end();
???iter.operator ++()) {
??cout << "| " << iter->first << " | " << iter->second << endl;
?}
}