-3

我试图使用地图向量调试编码(C++ / Quantlib)。基本上我想在地图内找到一个项目,该项目又在一个向量内。但发现错误。

输入:

vector<map <Date, Real> > simulatedPrices_;    // a vector containing 1000 maps
vector<Date> cds_maturities_;

私有变量:

map <Date, Real> pricePathJ;    // for reading each map in the vector
Real w_t_;    //

编码:

for (int j = 0; j < no_of_paths; j++) {
    pricePathJ = simulatedPrices_[j];
    for (int i = 0; i <= iTenor_; i++) {    //iTenor is the number of element inside vector cds_maturities_
        startDate = ......;
        endDate = ......;
        w_t_ = pricePathJ.find(cds_maturities_[i]);    // error in pricePathJ saying there is no conversion function from iterator ... the pair<Date, Real> to Real. 
        ......

我是否犯了任何错误,或者是否在上述编码中忽略了任何指针类型?谢谢。

备注:变量类型 Real 类似于 Double 类型

4

1 回答 1

0

您可以使用简单的 for 循环并使用 map 的find()函数来执行此操作。它将返回第一个Real匹配的

Real FindReal(const std::vector<std::map<Date, Real>> & data, const Date & findDate)
{
    for (auto&& e : data)
    {
        auto it = e.find(findDate);
        if (it != e.end())
            return it->second;
    }
    return some_value_if_not_found;
}
于 2015-04-14T16:50:18.980 回答