64,654
社区成员
发帖
与我相关
我的任务
分享
dataMap["data" + string(temp)];
时, 实际的动作为: 先在map中找, 如果没有找到了, 则返回相应的值, 如果没有找到, map对象会自动为你建立一个pair对象插入map中, 其中"键"为[]中的, "值" 如果是基本变量, 则赋值为0, 否则调用相应的构造函数
iterator lower_bound(const key_type& _Keyval) //这个是为_Where赋值的函数!
{ // find leftmost node not less than _Keyval in mutable tree
return (_TREE_ITERATOR(_Lbound(_Keyval)));
}
_Nodeptr _Lbound(const key_type& _Keyval) const
{ // find leftmost node not less than _Keyval ----说得很清楚
_Nodeptr _Pnode = _Root();
_Nodeptr _Wherenode = _Myhead; // end() if search fails ----很清楚
...
return (_Wherenode); // return best remembered candidate
}
#define _TREE_ITERATOR(ppnode) iterator(ppnode, this)
iterator(_Nodeptr _Pnode, const _Myt *_Plist=NULL)
: const_iterator(_Pnode, _Plist) //注意 class iterator:public const_iterator { // construct with node pointer _Pnode
}
_Where = this->insert(_Where, value_type(_Keyval, mapped_type()));
0041256A lea ecx,[ebp-14Ch]
00412570 call MapData::MapData (411168h)
...
004125DF mov ecx,dword ptr [ebp-14h]
004125E2 call std::_Tree<...>::insert (41132Fh)
...
0041262E lea ecx,[ebp-14Ch]
00412634 call MapData::~MapData (411172h)
MapData::MapData:
...
004121D5 mov ecx,dword ptr [this]
004121D8 call dword ptr [__imp_std::basic_string<...> (4243DCh)]
...
int main(){
map<string,short> words;
short value = words["key"];
map<string,short>::iterator it = words.begin();
cout<<(*it).first<<endl;
cout<<value<<endl;
return 0;
}