Answer the question
In order to leave comments, you need to log in
How to erase an element using vector.erase()?
How to remove an element that exceeds a certain value from a vector? (In this case, more than 9)
vector<int> myVector = { 1, 3, 10, 20, 13, 15, 4, 7, 9 , 18, 19, 1, 3 };
for (int i = 0; i < myVector.size(); i++) {
if (myVector[i] > 9) {
myVector.erase(...........) // как тут прописать?
}
}
Answer the question
In order to leave comments, you need to log in
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<short> myVector = { 1, 3, 10, 20, 13, 15, 4, 7, 9 , 18, 19, 1, 3 };
for (auto b = myVector.begin(); b!=myVector.end();)
{
if ((*b) > 9)
{
b = myVector.erase(b);
}
else b++;
}
for (const auto s : myVector)
{
cout << s << " ";
}
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question