首页 > 编程语言 > 详细

c++ 插入容器元素

时间:2018-12-12 13:40:36      阅读:150      评论:0      收藏:0      [点我收藏+]

 

#include <iostream>
#include <vector>
using namespace std;
int main ()
{
    vector<int> myints;
    cout << "0. size: " << myints.size() << \n;
    
    for (int i=0; i<10; i++) myints.push_back(i);
    cout << "1. size: " << myints.size() << \n;
    
    myints.insert (myints.end(),10,100);//起始位置,长度,填充元素
    cout << "2. size: " << myints.size() << \n;
    for (int i=0; i<20; i++) cout << myints[i]<<" ";
    myints.pop_back();
    cout << "\n3. size: " << myints.size() << \n;
    
    return 0;
}

 

c++ 插入容器元素

原文:https://www.cnblogs.com/sea-stream/p/10107814.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!