The code snippet below apparently tries to create three types of maps. The below code works really fine without the line commented out (This is the final hash that i would like to create). I would like to insert data into the final map myData , and when i uncomment the line below code doesnt work
data1.insert( std::make_pair( e_group[1]["ET"], m_wayside1) )
How to access the specific value in a set of a specific key
#include <map>
#include <iostream>
#include <string>
#include <vector>
#include <set>
struct values
{
std::string a;
std::string b;
values():a("milepost"),b("dummyval"){};
values( std::string ab, std::string bc)
{
a=ab;
b=bc;
};
};
typedef std::map<std::string,values> my_waysides ;
typedef std::map <int, std::set<std::string> > groups;
typedef std::map <groups,my_waysides> myData;
int main(int argc, const char * argv[]) {
my_waysides m_wayside1,m_wayside2,m_wayside3;
groups e_group,e_group1,e_group2;
values b,c,d;
std::set<std::string> myGroups;
myData data1;
myGroups.insert("ET");
myGroups.insert("PT");
e_group.insert( std::make_pair(1,myGroups) );
e_group.insert( std::make_pair(2,myGroups) );
e_group.insert( std::make_pair(3,myGroups) );
m_wayside1.insert(std::make_pair("7802543",b));
// data1.insert( std::make_pair( e_group[1]["ET"], m_wayside1) )
for (auto &i : e_group){
std::cout<<i.first<<"\t";
for (std::set<std::string> :: const_iterator it = i.second.begin() ; it != i.second.end() ; it++ )
{
std::cout<<*it<<"\t";
}
std::cout<<"\n";
}
std::cout << "Hello, World!\n";
return 0;
}
Aucun commentaire:
Enregistrer un commentaire