std::set_difference 中使用的 std:vector 中的断言错误
我试图找到两个向量的集合差,所以我做了这样的事情:
std::vector<sha1_hash> first_vec, second_vec, difference_vec;
// populate first_vec and second_vec ...
std::sort(first_vec.begin(),first_vec.end());
std::sort(second_vec.begin(),second_vec.end());
std::set_difference(first_vec.begin(),first_vec.end(),
second_vec.begin(),second_vec.end(),
difference_vec.begin());
当我在调试中运行它时,我得到以下运行时断言失败(在“向量”中):
_SCL_SECURE_VALIDATE_RANGE(_Myptr < ((_Myvec *)(this->_Getmycont()))->_Mylast);
我正在使用 VS 2008。 关于什么可以触发这个的任何想法?
I am trying to find the set difference of two vectors, so i do something like this:
std::vector<sha1_hash> first_vec, second_vec, difference_vec;
// populate first_vec and second_vec ...
std::sort(first_vec.begin(),first_vec.end());
std::sort(second_vec.begin(),second_vec.end());
std::set_difference(first_vec.begin(),first_vec.end(),
second_vec.begin(),second_vec.end(),
difference_vec.begin());
When i run this in debug, i get the following run-time assertion failure (in 'vector'):
_SCL_SECURE_VALIDATE_RANGE(_Myptr < ((_Myvec *)(this->_Getmycont()))->_Mylast);
I am using VS 2008.
Any ideas on what can trigger this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与大多数 C++ 算法一样,set_difference 不会在输出向量中创建以前不存在的新条目。 您需要在输出中创建空间来保存结果。
编辑:或者使用插入迭代器(以下未经测试):
Like most c++ algorithms, set_difference does not create new entries in the output vector where none existed before. You ned to create space in the output to hold the results.
Edit: Or use an an insert iterator (following untested):