20160804-CPP-map

来源:互联网 发布:js实现倒计时 编辑:程序博客网 时间:2024/05/21 07:04

map def: Constructs a list of a specific size or with elements of a specific value or with a specific allocator or as a copy of some other map.

1、map之间可以用 = 或者 ! = 来比较两个map之间是否相等, multimap也可以用。

map和multimap的区别

http://blog.csdn.net/cws1214/article/details/8211881

2、multimap <int, int> m1, m2, m3;

3、map之间也可以用<=, <, >=, > 

The less-than relationship between two objects is based on a comparison of the first pair of unequal elements.

4、swap( m1, m3 )
Exchanges the elements of two maps or multimaps.


关键的私有值

一个是key,用key来索引data value


有用的成员函数

5、at的使用 

map<char, int> Mymap; 
Mymap c1; 
c1.insert(value_type('a', 1));
cout << "c1.at('a') == " << c1.at('a') <<endl; 
6、begin()的使用
Returns an iterator that points to the first element in the map.
7、find()的使用
template <typename C, class T> void findit(const C& c, T val) {    cout << "Trying find() on value " << val << endl;    auto result = c.find(val);    if (result != c.end()) {        cout << "Element found: "; print_elem(*result); cout << endl;    } else {        cout << "Element not found." << endl;    }}
8、max_size()

max_size

Returns the maximum length of the map.

9. size()

size

Returns the number of elements in the map.

10、[ ]
// Insert a data value of 10 with a key of 1   // into a map using the operator[] member function   m1[ 1 ] = 10;



0 0