;second;
cout << map_it->second << endl;//2
set<int> iset{1,2,2,3,3,5};
set<int>::iterator set_it = iset.begin();
//*set_it = 10;//错误,不可以改变set的key
*/
//test3 遍历关联容器
/*
map<string, int> cnt{{"dd",1}, {"cc",2},{"aa", 10}};
map<string, int>::const_iterator map_it = cnt.cbegin();
while(map_it != cnt.cend()){
cout << map_it->first << ":" << map_it->second << endl;
++map_it;
}
for(auto &s : cnt){
cout << s.first << ":" << s.second << endl;
}
auto it = cnt.begin();
pair<string, int> p1 = *it;
*/
//test4 关联容器的通用算法
multiset<string> c{"aa","aa","dd","cc"};
vector<string> v{"ee","ff"};
//copy(v.begin(),v.end(), inserter(c, c.end()));//OK
//copy(v.begin(),v.end(), back_inserter(c));//NG,关联容器没有push_back
//copy(c.begin(),c.end(), inserter(v, v.end()));//OK,并且c的begin到end时拍好\\
序的
copy(c.begin(),c.end(), back_inserter(v));
for(auto &s : c){
cout << s << " ";
}
cout << endl;
for(auto &s : v){
cout << s << " ";
}
cout << endl;
return 0;
}
github完整代码
c/c++ 学习互助QQ群:877684253 本人微信:xiaoshitou5854
|