将矢量迭代器与整数进行比较
Compare vector iterator with integer
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 << "-" << " ";
这里cpy
是int
和string
对的vector
,即vector<pair<int,string>>cpy
。以上部分给出一个错误,即" pos不命名类型。"。
如何解决它?
您可以简单地将pos的类型更改为int。我认为您的编译器不完全支持自动。
相关文章:
- C++模板函数,用于比较任何无符号整数和有符号整数
- 正在LLVM中检测整数比较条件
- 为什么:不同符号的整数比较只是偶尔发生?
- C++ 如何比较n个排序的整数向量以找到互元素?
- 比较C++中两个整数的最有效和最干净的方法是什么?
- 禁止指针和整数之间的比较C++
- ISO C++禁止指针和整数 [-fpermissive] [c++] 之间的比较
- Qsort() 比较结构体整数的总和
- 比较两个整数在C++中与未知 int 类型的相等性
- Qt 错误 iso c++ 禁止指针和整数之间的比较 -permissive
- 比较整数提升后的结果
- 对压缩整数进行加法、减法和比较
- 如何正确比较整数和浮点值
- 错误:ISO C++禁止在指针和整数 [-fallowive] 之间进行比较
- 有效比较整数列表与C++中给定的整数
- 拉链比较整数和指针之间
- C 有效比较整数序列(相对顺序)
- 关于在C/C++中比较整数和浮点/双精度
- 什么更贵?读取或比较整数,双精度
- 从控制台输入c++,比较整数