小编Yii*_*iin的帖子

如果key已经存在,为什么stl map会插入另一个值,而不仅仅是更改它?

为什么我的程序使用STL映射在键已存在时插入值而不是更改现有值?

#include <iostream>
#include <map>

using namespace std;

struct CTest
{
    int a, b, c;
    CTest(int A, int B, int C) : a(A), b(B), c(C) {}
};

bool operator<(const CTest & l, const CTest & r)
{
    if(l.a < r.a) return true;
    else if(l.a > r.a) return false;

    if(l.b < r.b) return true;
    else if(l.b > r.b) return false;

    if(l.c < r.c) return true;
    else if(l.c > r.c) return false;

    return true;
}

struct CTest2
{
    bool operator<(const CTest2 & …
Run Code Online (Sandbox Code Playgroud)

c++ stl duplicate-data map

5
推荐指数
2
解决办法
962
查看次数

标签 统计

c++ ×1

duplicate-data ×1

map ×1

stl ×1