“vector iterator not incrementable” run-time error with set_intersection

删除回忆录丶 提交于 2019-12-05 19:51:12

result.begin() of an empty vector is not a valid output iterator. You need a back_inserter(result) instead.

#include <iterator>
...
set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), back_inserter(result));
cout << result.size() << endl;

Alternatively, resize result to at least 4, so that the vector can contain all results.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!