簡體   English   中英

使用迭代器的C ++ Vector of Maps如何

[英]C++ Vector of Maps using an iterator how to

如何為valuepair Set的每一行填充map的向量以及rowID或迭代器

比如說

typedef std::map<string, string> mapDB;
mapDB mapDB_colVal;
typedef mapDB::iterator mapDB_iter ;
vector<pair<int,mapDB> > mapDB_vec;

//populate mapDB_colVal 1st row
mapDB_colVal["X"]="APPLE";
mapDB_colVal["Y"]="RED";

How can I assign/populate 1st row mapDB_vec with mapDB_colVal

//populate mapDB_colVal 2nd row
mapDB_colVal["X"]="PEAR";
mapDB_colval["Y"]="RED";

任何想法都將非常感激。

謝謝

獅子座

簡而言之:

mapDB_vec.push_back(std::make_pair(0, mapDB_colVal));

更長:

你不需要那個rowID,矢量索引就夠了

更長時間:

struct Row {
    std::string x;
    std::string y;

    Row(std::string const& x_, std::string const& y_): x(x_), y(y_)
    {}
};

vector<Row> mapDB_vec;
mapDB_vec.push_back(Row("Apple", "Red"));
mapDB_vec.push_back(Row("Pear", "Red"));
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));

我不確定你想要的行ID。 如果它們只是序列號,那么它們似乎是多余的,因為向量允許您按位置識別元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM