logo CodeStepByStep logo

vectorMysteryRemove

Language/Type: C++ vector collections STL

What are the contents of the vector after the following code executes? Assume that a vector would print in the format {10, 20, 30}.

vector<int> vec;
for (int i = 1; i <= 8; i++) {
    vec += 10 * i;  //   0   1   2   3   4   5   6   7
}                   // {10, 20, 30, 40, 50, 60, 70, 80}
for (int i = 0; i < vec.size(); i++) {
    vec.erase(vec.begin() + i);
}
cout << vec << endl;
vector contents

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.