Structure your data in c++ using stl container map, set

how to orgnanize structure in a c++ program.

map of a {string–> pointing to a set of integer } and traverse all the string and element of set

A dumb and obvious solution:

// be careful about > > , single space between this two bracket

std::map<string, std::set<int> > strToIntSet;

// declare an iterator

std::map<string, std::set<int> >::iterator it;

for (it=strToIntSet.begin(); it!=strToIntSet().end(); it++){

std::cout<<it->first<<” : “;

std::set<int>::iteator it1;

// Now print out each element of set

for (it1=it->second.begin(); it1!=it->second.end(); it1++){

std::cout<<*it;
}
std::cout<<std::endl;

}

Assuming

Pretty simple.

Leave a Comment