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. 使用 WinHttp 实现文件下载

    #include <Windows.h> #include <Winhttp.h> #pragma comment(lib,"Winhttp.lib") t ...

  2. Bestcoder Round 47 && 48

    1.Senior's Array(hdu 5280) 题目大意:给出大小为N的数组和P,求将数组中的某个元素替换为P后的最大连续子段和.N<=1000 题解: 1.送分题,比赛的时候只想到枚举替 ...

  3. 394. Decode String

    [题目] Total Accepted: 10087 Total Submissions: 25510 Difficulty: Medium Contributors: Admin Given an ...

  4. Socket Receive 避免 Blocking

    我们知道 Socket Blocking 属性默认true . 表明Socket 处于同步调用 , Connect , 或 Send , Receive 需等待动作 完成才能继续执行. 有一种应用场景 ...

  5. Bootstrap<基础二十> 标签

    Bootstrap 标签.标签可用于计数.提示或页面上其他的标记显示.使用 class .label 来显示标签,如下面的实例所示: <!DOCTYPE html> <html> ...

  6. Spark机器学习读书笔记-CH03

    3.1.获取数据: wget http://files.grouplens.org/datasets/movielens/ml-100k.zip 3.2.探索与可视化数据: In [3]: user_ ...

  7. centos 下git服务器搭建

    准备 CentOS Linux release 7.0.1406 (Core) ssh 22端口 http 80端口 本文主要是ssh协议支持,http协议配置后还有问题. 摘抄的一段说明 SSH 协 ...

  8. Uncaught ReferenceError: XXX is not defined

    Uncaught ReferenceError: XXX is not defined 这个问题困扰我很久,虽然找到了解决方法,但是还不是很明白. 如下所示:是报错的代码. 如果把它改成下面的形式就可 ...

  9. struts2乱码

    在spring.jar包的org.springframework.web.filter包下有个CharacterEncodingFilter.java 把spring.jar放进工程的lib里,然后在 ...

  10. Android 开发常用命令

    1.生成keystore文件 keytool -exportcert -keystore keystore_path -list -v 2.查看APK签名 keytool -list -printce ...