集合联合不起作用
set union is not working
'left'是std::set的std::向量对于left中的每个元素(已设置),我试图通过在"left"上迭代来对另一个集合执行set并集操作。
为什么以下代码不起作用。我正在试着做两个集合的集合并集。
std::vector<std::set<int> > left(num_nodes);
//Both leftv and left are not empty ....there is some code here which fills them.
std::set<int> leftv, dummy;
for(std::set<int>::iterator u = leftv.begin(); u != leftv.end() ;u++){
dummy.insert(v); //v is some integer
std::set_union (left[*u].begin(), left[*u].end(), dummy.begin(), dummy.end(), left[*u].begin());
dummy.clear();
}
错误/usr/include/c++/4.3/bits/stl_alg.h:5078:错误:分配只读位置'__result.std::_Rb_tree_const_iterator<_Tp>::运算符*,带_Tp=int’
您试图通过将left[*u].begin()
作为set_union
的输出参数来覆盖集合的内容。集合中的元素不能修改,因为它们的值决定了它们在集合中的位置。即使可以,您也需要扩展容器以容纳额外的元素,而不是简单地覆盖现有的元素;并且输出必须不与任何一个输入范围重叠。总之:不能使用set_union
将一个集合的内容插入到另一个集合中。
如果要将dummy
的内容添加到left[*u]
,则插入每个元素:
std::copy(dummy.begin(), dummy.end(), std::inserter(left[*u]));
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 为什么这个位集集合算法不起作用
- 为什么此C 代码不起作用 - 试图删除集合中的元素时,请参考错误
- 集合迭代器的加号运算符不起作用
- 集合联合不起作用
- 在任意加长的集合中查找最大数不起作用