使用set<set>迭代器的编译错误<int>
compilation error using iterator of set<set<int> >
我认为我没有正确使用迭代器,但我看不出我的代码有什么问题:
#include <iostream>
#include <set>
#include <ctime>
#include <cstdlib>
#include <sstream>
int main(){
stringstream s;
set<int> a, b, c;
set<set<int> > d;
set<set<int> >::iterator pos;
srand(time(0));
d.insert(a);
d.insert(b);
d.insert(c);
for (pos = d.begin(); pos != d.end(); pos++){
for (int i=0;i<10;i++){
(*pos).insert(genInt(1,10));
}
s << "nSet: " << endl << *pos;
}
s << endl;
}
我试图用随机整数初始化这三个集,而成为另一组集合。
汇编错误在(*pos).insert(genInt(1,10))
中:
error: no matching function for call to ‘std::set<int>::insert(int) const’
genInt(1,10)
返回1到10之间的随机整数。
int genInt(int min, int max){
int tam = max - min + 1;
return ( (rand() % tam) + min);
}
您无法修改集合的元素。错误是正确的,没有 const insert
方法。
错误:呼叫'std :: set :: insert(int) const
no匹配函数
pos
是set
上的迭代器,只能提供const
对其所指元素的引用。因此,只能通过该参考来调用const
成员函数。std::set
以有序的方式存储它的元素,使其可以快速找到它们。更改其中一个要素会不安。在将其插入更大的集合之前,您必须完全构造子集。
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- EASTL矢量<向量<int>>连续的
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 什么是模板&lt;&gt;inline bla bla
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- eigen :: llt&lt;eigen :: matrixxd&gt;具有不完整的类型
- 错误,包括&lt; ctype&gt;在原子上使用C 11
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- 如何加入向量&lt; int&gt;到C 中的单个INT
- 是std :: set&lt; std :: future&gt;不可能存在
- 是numeric_limits&lt; int&gt; :: is_modulo从逻辑上矛盾
- opencv 2.4.7在iOS错误背景_segm.hpp #include&lt; list&gt;未找到
- 在修改列表后,std :: list&lt; t&gt; :: end()的值是否会更改
- ///<评论></评论>在Visual Studio中