c++ insert() 插入元素

#include 
#include 
#include 
#include 
using namespace std;
void display(vector &x) {
    vector::iterator it=x.begin();
    while (it!=x.end())
    {
        cout << *it << " ";
        it++;
    }
    cout << endl;
}

int main() {
    vector obD(5, 1);
    vector::iterator pD = obD.end();
    cout << "insert():";
    pD = obD.insert(pD, 5);
    display(obD);
    cout <<"after insert two elements before last element"<< endl;
    obD.insert(pD, 2, 7);
    display(obD);
    pD = obD.begin();
    //pD = obD.end();
    cout << "sz[3] to begin"<
c++ insert() 插入元素_第1张图片
2

你可能感兴趣的:(c++ insert() 插入元素)