开发者

C++ How to output values of Vector of Maps [duplicate]

开发者 https://www.devze.com 2023-02-16 02:37 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: C++ Vector of Maps using an iterator how to
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

C++ Vector of Maps using an iterator how to

This is a separate Qs on how to output values of a vector of Maps.

I have

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

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 ma开发者_JAVA技巧pDB_colVal 2nd row
mapDB_colVal["X"]="PEAR";
mapDB_colval["Y"]="GREEN";
db.push_back(make_pair(some_other_row_id, mapDB_colVal));

how can I output values inserted into db.

like this pseudo

for (db.begin;db.end;)
{ 
print db[i].begin; db[i].end }

How can I output the values stored in db . Any help will be great.

Thanks


for (mapDB_vec::iterator i = db.begin(); i != db.end(); ++i) {
   std::cout << i->first << ": " << std::endl;
   for (mapDB::iterator j = i->second.begin(); j != i->second.end(); ++j) {
      std::cout << "  " << j->first " - " << j->second << std::endl;
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号