C ++向量擦除函数说明

时间:2018-05-13 16:37:47

标签: c++ vector

我正在运行以下代码:

v1.assign(10,50);
v1.insert(v1.end(),22);
cout << "v1 > " << endl;
print(v1);
// prints 50 50 50 50 50 50 50 50 50 50 22
v1.erase(v1.begin()+2)v1.assign(10,50);
v1.insert(v1.end(),22);
cout << "v1 > " << endl;
print<int>(v1);

v1.erase(v1.begin()+2);

for (int i=0;i<11;i++)
    cout << v1[i] << " ";
cout << endl << endl;;

for (int i=0;i<11;i++)
    cout << v1[i] << " ";
cout << endl << endl;

据我所知,预期输出必须是:

50 50 50 50 50 50 50 50 50 22

(9次50次,1次22次)

但实际上是:

50 50 50 50 50 50 50 50 50 22 22

(9次50次)

0 个答案:

没有答案