1 #include<iostream>
 2 #include<vector>
 3 using namespace std;
 4 
 5 void print( vector<int> &vec )
 6 {
 7     for ( vector<int>::iterator it = vec.begin(); it!=vec.end(); it++ )
 8         cout<<*it<<' ';
 9     cout<<endl;
 }
 
 void push( vector<int> &vec, int value )
 {
     vec.push_back(value);
 }
 
 int main()
 {
     vector<int> first;
     vector<int> second (,); // four ints with value 100
     print(second);
     vector<int> third ( second.begin()+, second.end() );
     print(third);
     vector<int> fourth (third);
 
     //construct from arrays
     int arrays[] = {,,,,,};
     vector<int> fifth ( arrays, arrays + sizeof(arrays)/sizeof(int) );
 
     print(fifth);
     push(fifth, );
     print(fifth);
     fifth.pop_back();
     print(fifth);
     fifth.pop_back();
     print(fifth);
 
     cout<<"capacity is "<<fifth.capacity()<<endl;
     cout<<"size is "<<fifth.size()<<endl;
     fifth.reserve();
     cout<<"capacity is "<<fifth.capacity()<<endl;
     cout<<"size is "<<fifth.size()<<endl;
     print(fifth);
 
     // erase the first 3 elements:
     fifth.erase(fifth.begin(), fifth.begin()+);
     for (int i=; i<fifth.size(); i++ )
         cout<<fifth[i]<<' ';
     cout<<endl;
 
     return ;
 }

[c++] vector的使用的更多相关文章

  1. c++ vector 使用

    1. 包含一个头文件: 1 #include <vector> 2. 申明及初始化: std::vector<int> first; // empty vector of in ...

  2. Vector Tile

    Mapbox Vector Tile Specification A specification for encoding tiled vector data. <?XML:NAMESPACE ...

  3. ArrayList、Vector、LinkedList的区别联系?

    1.ArrayList.Vector.LinkedList类都是java.util包中,均为可伸缩数组. 2.ArrayList和Vector底层都是数组实现的,所以,索引数据快,删除.插入数据慢. ...

  4. ArrayList、Vector、HashMap、HashSet的默认初始容量、加载因子、扩容增量

    当底层实现涉及到扩容时,容器或重新分配一段更大的连续内存(如果是离散分配则不需要重新分配,离散分配都是插入新元素时动态分配内存),要将容器原来的数据全部复制到新的内存上,这无疑使效率大大降低. 加载因 ...

  5. Java中Vector和ArrayList的区别

    首先看这两类都实现List接口,而List接口一共有三个实现类,分别是ArrayList.Vector和LinkedList.List用于存放多个元素,能够维护元素的次序,并且允许元素的重复.3个具体 ...

  6. C++使用vector

    #include <iostream> #include <string> #include <vector> using namespace std; void ...

  7. [LeetCode] Flatten 2D Vector 压平二维向量

    Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [1,2], [3], [4,5,6] ] ...

  8. C++ 数组array与vector的比较

    转:http://blog.csdn.net/yukin_xue/article/details/7391897 1. array 定义的时候必须定义数组的元素个数;而vector 不需要: 且只能包 ...

  9. vector定义初始化

    头文件 #include<vector> using std::vector; vector<T> v1; vector<T> v2(v1); vector< ...

  10. vector迭代器用法

    #include<iostream> #include<vector> using namespace std; int main() { vector<int> ...

随机推荐

  1. CentOS 6.6编译安装Nginx1.6.2+MySQL5.6.21+PHP5.6.3

    http://www.osyunwei.com/archives/8867.html 一.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables #编辑防火墙配置 ...

  2. JSP之->初识JSP

    JSP 引用百度百科的介绍: JSP(Java Server Pages)是由Sun Microsystems公司倡导.许多公司参与一起建立的一种动态网页技术标准.JSP技术有点类似ASP技术,它是在 ...

  3. selenium+python+eclipse开发中遇到的问题

    1.中文编码问题 报错提示:SyntaxError: Non-ASCII character '\xba' in file D:\autotest\PythonCase\src\selenium\te ...

  4. 常用CSS样式

    1.line-height:行高.默认normal normal:允许内容顶开或溢出制定的容器边界; length:15px,可以为负数; ... 2.overflow:滚动条设置 overflow- ...

  5. 自定义javascript log方法

    /** * 类似chrome,firefox的console对象 * 但是在IE等不支持console的浏览器不会报错 * 理论上浏览器支持的console的方法都支持,比如谷歌的 * assert, ...

  6. angularjs的简单应用(一)

    AngularJS是为了克服html在构建应用上的不足而设计的.HTML是一门很好的为静态文本展示设计的声明式语言,但要构建WEB应用的话它就显得乏力了. AngularJS使用了不同的方法,它尝试去 ...

  7. SQLBulkCopy使用实例--读取Excel写入数据库/将 Excel 文件转成 DataTable

    MS SQL Server 提供一个称为 bcp 的流行的命令提示符实用工具,用于将数据从一个表移动到另一个表(表可以在不同服务器上). SqlBulkCopy 类允许编写提供类似功能的托管代码解决方 ...

  8. loadrunner四大部分

    loadrunner主要分一下四部分 1.VuGen  主要进行录制,回放,参数化,脚本修改,可以对脚本进行recording options,General options,runtime opti ...

  9. mov和ldr/str的区别

    ARM是RISC结构,数据从内存到CPU之间的移动只能通过L/S指令来完成,也就是ldr/str指令.比如想把数据从内存中某处读取到寄存器中,只能使用ldr比如:ldr r0, 0x12345678就 ...

  10. Hibernate的面试题

    1.Hibernate工作原理和为什么要用? 原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3.打开Session 4.创建事务Transation 5.持 ...