[c++] vector的使用
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的使用的更多相关文章
- c++ vector 使用
1. 包含一个头文件: 1 #include <vector> 2. 申明及初始化: std::vector<int> first; // empty vector of in ...
- Vector Tile
Mapbox Vector Tile Specification A specification for encoding tiled vector data. <?XML:NAMESPACE ...
- ArrayList、Vector、LinkedList的区别联系?
1.ArrayList.Vector.LinkedList类都是java.util包中,均为可伸缩数组. 2.ArrayList和Vector底层都是数组实现的,所以,索引数据快,删除.插入数据慢. ...
- ArrayList、Vector、HashMap、HashSet的默认初始容量、加载因子、扩容增量
当底层实现涉及到扩容时,容器或重新分配一段更大的连续内存(如果是离散分配则不需要重新分配,离散分配都是插入新元素时动态分配内存),要将容器原来的数据全部复制到新的内存上,这无疑使效率大大降低. 加载因 ...
- Java中Vector和ArrayList的区别
首先看这两类都实现List接口,而List接口一共有三个实现类,分别是ArrayList.Vector和LinkedList.List用于存放多个元素,能够维护元素的次序,并且允许元素的重复.3个具体 ...
- C++使用vector
#include <iostream> #include <string> #include <vector> using namespace std; void ...
- [LeetCode] Flatten 2D Vector 压平二维向量
Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [1,2], [3], [4,5,6] ] ...
- C++ 数组array与vector的比较
转:http://blog.csdn.net/yukin_xue/article/details/7391897 1. array 定义的时候必须定义数组的元素个数;而vector 不需要: 且只能包 ...
- vector定义初始化
头文件 #include<vector> using std::vector; vector<T> v1; vector<T> v2(v1); vector< ...
- vector迭代器用法
#include<iostream> #include<vector> using namespace std; int main() { vector<int> ...
随机推荐
- linux与php时间函数有关的错误解决
最近在程序里写了不少获取时间或时间戳的函数date() strtotime()等,但是把程序拿到linux上运行却爆出这些函数的错误,具体原因是因为linux本身的时间设置以及php的时区问题. 先确 ...
- VBA续嘘嘘
什么是VBA?它有什么作用? A.实现Excel中没有实现的功能. B.提高运行速度. C.编写自定义函数. D.实现自动化功能. E.通过插入窗体做小型管理软件. VBA在哪里存放的?怎么运行? A ...
- html图片预览
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- protocol的简单写法
// // TouchView.h // LessonUIControlAndSubClass #import <UIKit/UIKit.h> @class TouchView; //1. ...
- http://tool.oschina.net 在线API文档库java jquery ,php,很全的文档库
http://tool.oschina.net 1.6API文档(中文)的下载地址: ZIP格式:http://download.java.net/jdk/jdk-api-localizations ...
- Eclipse_luna_J2EE_For_JS+tomcat8.0环境搭建、配置、开发入门
一.所有需要的软件.插件等下载地址 J2SE的官方下载路径:http://www.oracle.com/technetwork/java/javase/downloads/index.html Ecl ...
- JS 笔记(二) - 函数
1. 函数的 声明 1) 声明式写法 function j1(id){ alert(id); } 2) 声明匿名函数变量 var j2 = function (a, b) { alert(a + &q ...
- C++程序内存泄漏检测方法
一.前言 在Linux平台上有valgrind可以非常方便的帮助我们定位内存泄漏,因为Linux在开发领域的使用场景大多是跑服务器,再加上它的开源属性,相对而言,处理问题容易形成“统一”的标准.而在W ...
- SSH框架
一,Struts2框架部署 1,搭建Struts2的jar包 1.1,Struts2所需各个jar包的作用 asm-3.3.jar 操 ...
- 调试 zeromq 发现 accept 死循环
起因:在群里一个同学说使用 zeromq 的时候出了点儿问题,问题描述如下“router连接十几万客户端后,然后把router杀死,重启,这时候zeromq的某个线程99%的cpu,卡死了,再也接受不 ...