c++ - I need help while inserting in a map of integer and set of a structure -
the code :
#include <map> #include <utility> typedef struct { int d_number; int o_number; } d_o_pair; std::set<d_o_pair> d_o_set; std::map<int, d_o_set> my_map; }
i want insert map. not able to
. using : this->my_map[5].insert(make_pair(0, 2)). compiler throws me error telling no function matches call insert
following sample code tell inserting map. inserting set, need overload '<' operator define ordering condition in structure constructor , insert in similar fashion using insert function.
#include<iostream> #include<map> using namespace std; typedef struct { int d_number; int o_number; }d_o_number; int main() { d_o_number s1; s1.d_number = 100; s1.o_number = 1000; std::map<int, d_o_number> d_o_map; d_o_map.insert(std::pair<int, d_o_number>(0, s1)); // showing contents: std::map<int,d_o_number>::iterator = d_o_map.begin(); std::cout << "d_o_map contains:\n"; (it=d_o_map.begin(); it!=d_o_map.end(); ++it) std::cout << it->first << " => " << it->second.d_number<<","<<it->second.o_number << '\n'; return 0; }
Comments
Post a Comment