#include #include using namespace std ; int main() { map first; first['a']=10; first['b']=30; first['c']=50; first['d']=70; map::iterator iter = first.begin() ; for(; iter != first.end() ; iter++) cout << iter->first << " " << iter->second << endl ; cout << endl ; map second (first.begin(),first.end()); map::iterator iter2 = second.begin() ; for(; iter2 != second.end() ; iter2++) cout << iter2->first << " " << iter2->second << endl ; cout << endl ; map third (second); map::iterator iter3 = third.begin() ; for(; iter3 != third.end() ; iter3++) cout << iter3->first << " " << iter3->second << endl ; return 0 ; }
#include #include using namespace std ; int main() { multimap first; //可以一键对应多值 first.insert(pair('a',10)); first.insert(pair('b',20)); first.insert(pair('b',30)); map::iterator iter = first.begin() ; for(; iter != first.end() ; iter++) cout << iter->first << " " << iter->second << endl ; cout << first.count('b') << endl ; //键值出现的次数 multimap::iterator iterr ; iterr = first.find('a') ; // 查找关键字位置 first.erase(iterr) ; // 删除该关键字 map::iterator iter3 = first.begin() ; for(; iter3 != first.end() ; iter3++) cout << iter3->first << " " << iter3->second << endl ; return 0 ; }