小编Sid*_*Sid的帖子

我想在迭代它时对std :: map进行就地修改

我需要知道对地图进行原位修改的最佳方法,而不需要修改值的本地副本,然后将其再次推送到原始地图中.

我已经详细介绍了下面解释问题的代码段:

#include <string>
#include <map>
struct EmployeeKey
{
    std::string name;
    int amount;
    int age;
};

struct EmployeeDetail
{
    std::string dept;
    int section;
    int salary;
};

bool compareByNameAge(const std::string& name,
                      const int& age,
                      const EmployeeKey& key )
{
    return name > key.name && age > key.age;
}

typedef std::map<EmployeeKey, EmployeeDetail> EmployeeMap;

int main()
{
    EmployeeMap eMap;
    // insert entries to the map
    int age = 10;
    std::string name = "John";

    EmployeeMap transformMap;
    foreach( iter, eMap )
    {
        if ( compareByNameAge(name, …
Run Code Online (Sandbox Code Playgroud)

c++

5
推荐指数
3
解决办法
4294
查看次数

标签 统计

c++ ×1