I'm trying to solve a problem in C++, a part of which requires me to erase elements from a vector using the rbegin()
member function. However, the compiler throws an error every time I write the below-mentioned code. What's wrong here?
int main() {
int a = 1, b = 2;
vector<int> V = {a, b};
auto it = V.rbegin();
V.erase(it);
return 0;
}
It compiles just fine, however, if I access the same element using the begin()
member function. The code below works fine.
int main() {
int a = 1, b = 2;
vector<int> V = {a, b};
auto it = V.begin()+1;
V.erase(it);
return 0;
}