在一个map中查找一个值,没有的话插入,有的话,取出。只查找一次map的做法

 

 

 

 

     ////找出值小于等于uTypeID的第一个数,如果没找到,it已经是下一个需要插入的位置

        MyMap::iterator it = list->lower_bound( uTypeID );
    
if(  it != list->end() && (it->first==uTypeID)  )
    {
             
///找到了
        value = it->second;
    }
    
else
    {
            value
=new value();
            
/////记得给it参数,表示插入的位置
        pblist->insert(  it, MyMap::value_type( uTypeID, value)  );
    }

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
猜你喜欢
  • 2022-01-19
  • 2021-06-14
  • 2021-10-26
  • 2022-02-09
  • 2022-12-23
  • 2021-10-14
  • 2021-10-31
相关资源
相似解决方案