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

时间:2017-09-07 13:01:59

标签: c++ vector

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 << "-" << " ";

此处cpyvector intstring对的vector<pair<int,string>>cpy,即{{1}}。 上面的部分给出了一个错误,&#34; pos没有命名类型。&#34;。
如何解决?

1 个答案:

答案 0 :(得分:0)

您只需将pos类型更改为int即可。我认为你的编译器并不完全支持auto。

相关问题