lundi 27 mars 2017

how to print std::set of std::maps

Here is the map with a string key and a structure value 1. Firsly Iam creating a map of integer and a structure as value std::map<int,struct value>; and then iam adding all these map objects to a set std::set<std::map<int,struct value>> and i would like to understand how to loop through this set Iam not able to access the maps that are the part of this set, please suggest

struct values
{
    std::string a;
    std::string b;
    values():a("milepost"),b("dummyval"){};
    values( std::string ab, std::string bc)
    {
        a=ab;
        b=bc;

    };

    bool operator<(const values& other) const {
         return (a< other.a && b < other.b) ;
         }
    friend std::ostream& operator<<(std::ostream& os, const values& val);

};
std::ostream& operator<< (std::ostream& os , const values& val)
{
  os << val.a <<"\t"<< val.b;
  return os;

}
 typedef std::map<std::string,values>  myWsData;
main() 
{
    values a;

    myWsData et_Data1,pt_Data2;

    et_Data2.insert(std::make_pair("780256", a));

    pt_Data2.insert(std::make_pair("780256", a));

    std::set<myWsData> myet_pt_data;

    myet_pt_data.insert(et_Data1);

    myet_pt_data.insert(pt_Data2);

    for (auto &i:myet_pt_data)
    {
      std::cout<<i<<"\n";
    }


}

Aucun commentaire:

Enregistrer un commentaire