[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> ...
随机推荐
- React + Redux 入坑指南
Redux 原理 1. 单一数据源 all states ==>Store 随着组件的复杂度上升(包括交互逻辑和业务逻辑),数据来源逐渐混乱,导致组件内部数据调用十分复杂,会产生数据冗余或者混用 ...
- [开发笔记]-未找到与约束ContractName Microsoft.VisualStudio.Text.ITextDocumentFactoryService...匹配的导出【转载自:酷小孩】
原文地址:http://www.cnblogs.com/babycool/p/3199158.html 今天打算用VisualStudio2012做一个js效果页面测试的时候,打开VS2012新建项目 ...
- Yii 多个子目录同步登录
---恢复内容开始--- 配置文件中: 1 'components'=>array( 'user'=>array( 'class'=>'CWebUser', 'identityCo ...
- <script type="text/javascript" src="<%=path %>/pages/js/arsis/area.js?v=1.01"></script> 为什么在最后加? v+1.01
不写也可以 是为了js改变以后 ,名字未变 ,如果原来有的浏览器加载 了,遇到相同名字的就是引用缓存,不在从新加载.会出现错误.加上后 会重新加载. css 引用后面也一样.
- Request 请求页面的地址路径获取
Request.ApplicationPath: /testweb Request.CurrentExecutionFilePath: /testweb/default.aspx Request.Fi ...
- snort installation, configuration and test
snort installation: https://www.snort.org/#get-started wget https://www.snort.org/rules/snortrules-s ...
- .NET笔试题集(二)
1.using关键字有什么用?什么是IDisposable? using可以声明namespace的引入,还可以实现非托管资源的释放,实现了IDisposiable的类在using中创建,using结 ...
- mysql 导出导入数据库
导入mysql -u$USER -p$PASSWD -h127.0.0.1 -P3306 --default-character-set=utf8 < db.all.sql导出 mysqldum ...
- 一款公用的CSS+DIV弹窗
为了方便以后自己使用! <html> <head> <style> .winmainshow { background: #fff; padding: 10px 5 ...
- firefox vimperator插件
firefox vimperator插件实在是强大,最喜欢的几个功能做个笔记. 如何复制网页上的文字:c进入caret模式,定位cursor到要复制的开始位置--v进入visual模式,用hjkl键选 ...