Reputation: 61
//I am reading data from file and storing data into structure.Here "obj" is a object of structure.
Also note that my file have outer map key multiple times means when i am reading from file then some field of structure has common value and i am using that common value as a key of outer loop.
If I have only single value of outer key then it works fine but when more than one value of key then it fails.
typedef std::map<double,Order_Msg,std::greater<double> >InnerMap;
typedef std::map<int, InnerMap> OuterMap;
InnerMap buy_detailsmap;
OuterMap buy_tokenmap;
//one way
buy_tokenmap.insert(make_pair(obj.token,InnerMap()));
buy_detailsmap.insert(make_pair(obj.orderId,obj));
//another way
buy_detailsmap.insert (std::pair<double,Order_Msg>(obj.orderId,obj));
buy_tokenmap.insert(std::make_pair(obj.token,buy_detailsmap));
I tried both but its not working properly.
Upvotes: 1
Views: 1296
Reputation: 227608
It isn't clear why you need buy_detailsmap
, as it is de-coupled from buy_detailsmap
. Unless you really need insert
's semantics, you could simply use operator[]
:
buy_tokenmap[obj.token][obj.orderId] = obj;
Upvotes: 2