STL_map.修改删除

1、修改示例

int TdrSvgAttr::AttrSet_mem(bool _bAttrInStyle, string &_strAttrName, string& _strAttrValue)
{
    map<string, string> *pMap = NULL;
    if (_bAttrInStyle)
        pMap = &FmapStyle;
    else
        pMap = &FmapNormal;

    if (pMap != NULL)
    {
        map<string, string>::iterator it = pMap->find(_strAttrName);
        if (it == pMap->end())
            pMap->insert(std::make_pair(_strAttrName, _strAttrValue));
        else
        {
            // ZC: 两种修改 value的方式
            it->second = _strAttrValue;
            //FmapStyle[_strAttrName] = _strAttrValue;
        }
    }

    return 0;
}

2、删除示例

int TdrSvgAttr::AttrRemove_mem(bool _bAttrInStyle, string &_strAttrName)
{
    map<string, string> *pMap = NULL;
    if (_bAttrInStyle)
        pMap = &FmapStyle;
    else
        pMap = &FmapNormal;

    if (pMap != NULL)
    {
        map<string, string>::iterator it = pMap->find(_strAttrName);
        pMap->erase(it);
    }
    return 0;
}

3、

4、

5、

猜你喜欢

转载自www.cnblogs.com/cppskill/p/9317088.html
今日推荐