将矢量迭代器与整数进行比较

Compare vector iterator with integer

本文关键字:比较 整数 迭代器      更新时间:2023-10-16
string str = cpy[i].second;
itr = find(v.begin(), v.end(), str);
auto pos = distance(v.begin(), itr);
//auto pos = itr - v.begin();
if(pos >= v.size() / 2)
    cout << str << " ";
else
    cout << "-" << " ";

这里cpyintstring对的vector,即vector<pair<int,string>>cpy。以上部分给出一个错误,即" pos不命名类型。"。
如何解决它?

您可以简单地将pos的类型更改为int。我认为您的编译器不完全支持自动。