visual studio - Finding items inside a vector of map given a key (C++) -
i trying debug coding (c++ / quantlib) using vector of maps. find item inside map in turn inside vector. caught error.
input:
vector<map <date, real> > simulatedprices_; // vector containing 1000 maps vector<date> cds_maturities_;
private variable:
map <date, real> pricepathj; // reading each map in vector real w_t_; //
coding:
for (int j = 0; j < no_of_paths; j++) { pricepathj = simulatedprices_[j]; (int = 0; <= itenor_; i++) { //itenor number of element inside vector cds_maturities_ startdate = ......; enddate = ......; w_t_ = pricepathj.find(cds_maturities_[i]); // error in pricepathj saying there no conversion function iterator ... pair<date, real> real. ......
did commit mistakes or if there's pointer type overlooked in above coding? thanks.
remarks: variable type real simular type double
you can use simple loop , use map's find()
function this. return first real
matches
real findreal(const std::vector<std::map<date, real>> & data, const date & finddate) { (auto&& e : data) { auto = e.find(finddate); if (it != e.end()) return it->second; } return some_value_if_not_found; }
Comments
Post a Comment