C++ How to output values of Vector of Maps [duplicate]
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;
}
}
精彩评论