使用迭代器的C ++ Maps Vector如何 [英] C++ Vector of Maps using an iterator how to

查看:56
本文介绍了使用迭代器的C ++ Maps Vector如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为地图的向量以及rowID或值对Set的每一行的迭代器填充

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

例如

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";

任何想法都会受到赞赏.

Any ideas would be most appreciated.

谢谢

狮子座

推荐答案

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.如果它们只是序号,那么它们似乎是多余的,因为向量允许您通过其位置识别元素.

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.

这篇关于使用迭代器的C ++ Maps Vector如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆