Map usage in C ++ and map usage in C ++
/*************************************** *********************************
*
* Map features: 1. Store Key-value pairs
* 2. Quick search is supported. The search complexity is basically Log (N)
* 3. Fast insertion, fast deletion, and quick Modification
*
/*************************************** *********************************/
# 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 <"first element is:" <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;
}
Running result
Source http://www.cnblogs.com/anywei/archive/2011/10/27/2227009.html