map

xiaoxiao2021-02-27  273

#include <iostream> #include <map> #include <string> using namespace std; template<class t1, class t2> void outMap(map<t1, t2> &m) { typename map<t1, t2>::iterator it; for (it = m.begin(); it != m.end(); it++) { cout << it->first << "," << it->second << endl; } } void main() { //key , value map<int, string> myMap; myMap.insert(make_pair(2, "li")); myMap.insert(make_pair(1, "zhang")); myMap.insert(make_pair(2, "li2")); myMap[3] = "wang"; myMap[4] = "zhao"; //myMap.erase(maMap.begin()+n); //+n error; //myMap.erase(maMap.begin()+=1); //+= error; //myMap.erase(++maMap.begin()); //ok myMap.erase(2); myMap.erase(myMap.find(3)); outMap(myMap); }
转载请注明原文地址: https://www.6miu.com/read-14677.html

最新回复(0)