1. 程式人生 > >vector查詢資料並返回索引

vector查詢資料並返回索引

vector<double>::iterator ite1 = find(vec_dis.begin(), vec_dis.end(), vec_dis1[0]);
vector<double>::iterator ite2 = find(vec_dis.begin(), vec_dis.end(), vec_dis1[1]);
vector<double>::iterator ite3 = find(vec_dis.begin(), vec_dis.end(), vec_dis1[2]);
auto index1 = std::distance(std::begin(vec_dis), ite1);
auto index2 = std::distance(std::begin(vec_dis), ite2);
auto index3 = std::distance(std::begin(vec_dis), ite3);