I am trying to rotate a vector of elements in C++. What I mean by that is that I have a vector<point> I want the last element to become the first.
Example:
[1,2,3] become [3,1,2] then [2,3,1]
For that I tried to do the following:
//Add the last element at index 0
ObjectToRotate.insert(0, ObjectToRotate.at(ObjectToRotate.size()-1));
//Remove Last element
ObjectToRotate.erase(ObjectToRotate.size()-1);
but I get this error:
Error 6 error C2664: ‘std::_Vector_iterator<_Myvec> std::vector<Ty>::insert<cv::Point<_Tp>&>(std::_Vector_const_iterator<_Myvec>,_Valty)’ : cannot convert parameter 1 from ‘int’ to ‘std::_Vector_const_iterator<_Myvec>’
How can I solve it?
There’s a
std::rotatealgorithm in the standard library: