C++ Vector of Maps using an iterator how to

前端 未结 2 1235
时光取名叫无心
时光取名叫无心 2021-01-26 12:36

How can I populate a vector of map along with a rowID , or an iterator for each row of a valuepair Set

Like for example

typedef std::map

        
2条回答
  •  难免孤独
    2021-01-26 13:01

    mapDB_vec db;
    
    //populate mapDB_colVal 1st row
    mapDB_colVal["X"]="APPLE";
    mapDB_colVal["Y"]="RED";
    db.push_back(make_pair(some_row_id, mapDB_colVal));
    
    //populate mapDB_colVal 2nd row
    mapDB_colVal["X"]="PEAR";
    mapDB_colval["Y"]="RED";
    db.push_back(make_pair(some_other_row_id, mapDB_colVal));
    

    I'm not sure what row IDs you want. If they're just sequential numbers, then they would seem redundant, since vectors allow you to identify elements by their position.

提交回复
热议问题