std::reverse 的替代方法来保留向量中的所有元素?

Bot*_*yok 0 c++

std::vector<int> temp;
temp.insert(temp.begin(), points1.begin(), points1.end());
points1.clear();
std::vector<int> points1(temp.end(), temp.begin());
temp.clear();
Run Code Online (Sandbox Code Playgroud)

我试过这个,但我有一个异常连接到内存分配。

Geo*_*roy 7

用于std::rbegin以相反的顺序迭代。

如果你尝试points1(temp.end(), temp.begin());,它从非法迭代器开始(结束......)。

此外,您在points1提供的代码中再次声明