20160804-CPP-map

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值