相关疑难解决方法(0)

"不匹配运算符 - "简单迭代器差异的错误

这是我的代码:

#include <set>
#include <iostream>
using namespace std;

int main(){
    set<int> st;
    st.insert(1);
    int x = st.find(1) - st.begin();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我到了error: no match for 'operator-' in 'st.std::set<_Key, _Compare, _Alloc>::find [with _Key = int, _Compare = std::less<int>, _Alloc = std::allocator<int>](((const int&)((const int*)(&1)))) - st.std::set<_Key, _Compare, _Alloc>::begin [with _Key = int, _Compare = std::less<int>, _Alloc = std::allocator<int>]()'.

我无法弄清楚迭代器差异是如何突然停止工作的!我在这里错过了什么吗?

c++ iterator const-iterator c++11 c++14

1
推荐指数
2
解决办法
1396
查看次数

标签 统计

c++ ×1

c++11 ×1

c++14 ×1

const-iterator ×1

iterator ×1