/************************************************************************ * * Map features: 1, Storage key-value to * 2, support for quick lookup, The complexity of the lookup is basically log (N) * 3, quick Insert, quick Delete, quick change note* /************************************************************************/#include <iostream> #include <
String> #include <map> using namespace std;
int main () {map<const char*,int> m;
M["a"]=1;
m["B"]=6;
m["C"]=9;
Map<const Char*,int>::iterator it;
It=m.begin ();
Const char* C =it->first;
cout<< "A:" <<c<<endl;
int i = m["C"]; while (It!=m.end ()) {cout << it->first<< ";"
<<it->second<<endl;
++it;
} cout << "m[\" c\ "]=" <<i<<endl;
cout << "sizeof m:" <<m.size () <<endl;
cout << "Erase m[\" c\ "] (1:succ 0:failed):" <<m.erase ("C") <<endl;
cout << "Erase m[\" c\ "]:" <<m.erase ("C") <<endl;
cout << "sizeof m:" <<m.size () <<endl;
cout<< "m[c]=" <<m["C"]<<endl;
cout<< "sizeof m:" <<m.size () <<endl;
return 0; }
Run results
The above is a small series to bring you in-depth understanding of C + + map usage of all content, I hope that we support cloud-Habitat Community ~