stlmap - C++ map not inserting properly -
i trying populate map following structs:
struct counterparty { uint8_t firm_id; char trader_tag[3]; uint32_t qty; }; struct orderfillmessage { header header; uint32_t order_id; uint64_t fill_price; uint32_t fill_qty; uint8_t no_of_contras; std::vector<counterparty> counterpartygroup; char termination_string[8]; }; void tradedecoder::findmostactivetrader() { map<char*,int> traders_volume_map; for(orderfillmessage m: orderfillmessages) { for(counterparty cp: m.counterpartygroup) { outputfile<<cp.trader_tag<<" "<<cp.qty<<endl; traders_volume_map[cp.trader_tag]+=cp.qty; } } outputfiletrader<<"printing map "<<traders_volume_map.size()<<"\n"; for(auto it=traders_volume_map.begin(); it!=traders_volume_map.end(); it++) { outputfiletrader<<(it)->first<<(it)->second<<endl; } }
as can see, simple insert or update map function.
outputfile<<cp.trader_tag<<" "<<cp.qty<<endl;
prints following:
iyh 2 htc 1 iyh 2 htc 1 iyh 2 htc 1 iyh 1 htc 1 iyh 1 htc 1 iyh 1 htc 1 iyh 1 htc 1 iyh 1
however outputfiletrader<<"printing map "<
printing map 1 htc3050
which means nothing added map, , found though there 1 element in map!?
any insights why happening appreciated!!
thanks
i want add that, trader_tag of char[3], not null terminated. however, not think cause map issue
you using char *
key. bad idea vary considerably.
use following
map<std::string, int> traders_volume_map;
to overcome problem.
Comments
Post a Comment