读书人

stl map 的 iterator insert( iterato

发布时间: 2012-03-17 19:06:28 作者: rapoo

stl map 的 iterator insert( iterator pos, const pair<KEY_TYPE,VALUE_TYPE> &val );
iterator insert( iterator pos, const pair<KEY_TYPE,VALUE_TYPE> &val );

这个 pos 是做什么用的?

map 是自动排序的要这个 pos 干嘛?

[解决办法]
pair<iterator,bool> insert ( const value_type& x );
iterator insert ( iterator position, const value_type& x );

position
Position of the first element to be compared for the insertion operation.
Notice that this does not force the new element to be in that position within the map container (elements in a set always follow a specific ordering), but this is actually an indication of a possible insertion position in the container that, if set to the element that precedes the actual location where the element is inserted, makes for a very efficient insertion operation.
iterator is a member type, defined as a bidirectional iterator type.

http://www.cplusplus.com/reference/stl/map/insert/

读书人网 >C++

热点推荐