开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜