【发布时间】:2020-05-11 08:44:36
【问题描述】:
我正在尝试使用 STL 提供的二进制搜索功能,该功能需要首先对向量进行排序。所以这就是为什么我试图直接使用 Set 所以我不必先排序。
但是当按如下方式设置时,
`
#include <bits/stdc++.h>
using namespace std;
int main(){
set <int> mn = {11, 33, 44, 66, 80,90};
auto it= mn.lower_bound(55);
cout<<it-mn.begin();
return 0;
}
`
发生错误:
错误:“operator-”不匹配(操作数类型为“std::_Rb_tree_const_iterator”和“std::set::iterator”
这里如何使用set获取返回的迭代器的索引号?
PS:我也尝试过使用 set::lower_bound,但显示相同的错误。
【问题讨论】:
标签: c++ stl binary-search stdset