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. Basic linux command-with detailed sample

    Here I will list some parameters which people use very ofen, I will attach the output of the command ...

  2. python 类、对象、方法、属性

    在python中,一个对象的特征也称为属性(attribute).它所具有的行为也称为方法(method) 结论:对象=属性+方法 在python中,把具有相同属性和方法的对象归为一个类(class) ...

  3. 八皇后java算法

    import java.util.Date; public class EightQueen { public static void main(String[] args) {  long star ...

  4. 重置了下系统好多关于mysql密码的文章都很渣拷分好的备用

    方法1: 用SET PASSWORD命令 mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass ...

  5. vmware虚拟机网络自动断开的问题

    最近搭建一个集群环境,因此用vmware安装了几台虚拟机,系统是centos7.2. 但是发现网络总是不经意间自动断开,重启网络(service network restart)恢复. 虚拟机网络类型 ...

  6. 对ToString("X2 ")的理解

    /// <summary>        /// 将byte型转换为字符串        /// </summary>        /// <param name=&q ...

  7. 第3.2 使用案例1:股票期货stock portfolio 21050917

    As mentioned earlier in the chapter, the first use case revolves around a stock portfolio use case  ...

  8. Unreal Engine Plugin management

    Be aware to remove any dependencies to any modules related to Editor, or else it will end up with fa ...

  9. shell 简单的比大小脚本

    #!/bin/bash echo "第一个数字" read a echo "第二个数字" read b if [ $a -gt $b ] then echo & ...

  10. SparkSQL读取Hive中的数据

    由于我Spark采用的是Cloudera公司的CDH,并且安装的时候是在线自动安装和部署的集群.最近在学习SparkSQL,看到SparkSQL on HIVE.下面主要是介绍一下如何通过SparkS ...