C++———Vector
#include<algorithm>
#include <vector>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;
typedef struct rect
{
int id;
int length;
int width; //对于向量元素是结构体的,可在结构体内部定义比较函数,下面按照id,length,width升序排序。
bool operator< (const rect &a) const
{
if(id!=a.id)
return id<a.id;
else
{
if(length!=a.length)
return length<a.length;
else
return width<a.width;
}
}
}Rect; int main()
{
std::vector<int> vecc;
for(int i=;i<;i++){
vecc.push_back(i);
} cout<<vecc[]<<endl;
vector<int> ::iterator itt;
for(itt=vecc.begin();itt!=vecc.end();itt++){
cout<<*itt<<endl;
}
vecc.insert(vecc.begin()+,);
cout<<vecc[]<<endl;
vecc.erase(vecc.begin()+);
cout<<vecc[]<<endl; vector<Rect> vec;
Rect rect;
rect.id=;
rect.length=;
rect.width=; vec.push_back(rect); vector<Rect>::iterator it=vec.begin();
cout<<(*it).id<<' '<<(*it).length<<' '<<(*it).width<<endl; getch();
return ;
}
#include "opencv2/objdetect.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;
using namespace cv;
int main()
{
std::vector<int> vec;
vec.push_back();
vec.push_back();
vec.push_back();
vec.push_back();
cout<<vec[]<<endl;
vector<int>::iterator it;
for(it=vec.begin();it!=vec.end();it++){
cout<<"vector:"<<*it<<endl;
}
vec.insert(vec.begin()+,);
cout<<vec[]<<endl;
vec.erase(vec.begin()+);
cout<<vec[]<<endl;
cout<<vec.size()<<endl; getch();
return ;
}

#include<stdio.h>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std; typedef struct rect
{
int id;
int length;
int width; //对于向量元素是结构体的,可在结构体内部定义比较函数,下面按照id,length,width升序排序。
bool operator< (const rect &a) const
{
if(id!=a.id)
return id<a.id;
else
{
if(length!=a.length)
return length<a.length;
else
return width<a.width;
}
}
}Rect; int main()
{
vector<Rect> vec;
Rect rect;
rect.id=;
rect.length=;
rect.width=;
vec.push_back(rect);
vector<Rect>::iterator it=vec.begin();
cout<<(*it).id<<' '<<(*it).length<<' '<<(*it).width<<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> ...
随机推荐
- apache2.4+php7.3.2+mysql5.7
一.下载php7和apache2.4 1 首先下载php7的windows压缩包,到这里下载http://windows.php.net/download/ 我选择的是php7的这个版本,由于它是vc ...
- Ext 行统计有意思的实现.(js对象的循环, ext列的设置)
考勤界面, 列包含日期. 行的数据格式: 需要实现 编辑一列然后在最后产生的统计的效果. 行数据内容. Gird Load 的时候统计数据: -- 根据对象. 可以Ext.Date.parse 成 ...
- 关于Spring的Quartz定时器设定
在实际的开发业务中经常会遇到定时执行某个任务,如果项目使用的ssh框架的话,就需要配合spring来使用定时器.spring的定时器是一个固定的配置格式,具体的applicationContext配置 ...
- javascript websocket 心跳检测机制介绍
====测试代码: ==index.html <!DOCTYPE html> <html lang="en"> <head> <meta ...
- WPF常用TriggerAction用法 (一)
Microsoft.Expression.Interactivity 常用TriggerAction-> CallMethodAction ChangePropertyAction Contro ...
- [C#]左移和右移
参考链接: https://www.cnblogs.com/tjudzj/p/4190878.html https://www.cnblogs.com/wwwzzg168/p/3570152.html ...
- matlab-霍夫变换详解(判断正方形长方形)
霍夫变换 霍夫变换是1972年提出来的,最开始就是用来在图像中过检测直线,后来扩展能检测圆.曲线等. 直线的霍夫变换就是 把xy空间的直线 换成成 另一空间的点.就是直线和点的互换. 我们在初中数学中 ...
- MySQL(Python+ORM)
本篇对于Python操作MySQL主要使用两种方式: 原生模块 pymsql ORM框架 SQLAchemy pymsql pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb ...
- TCP协议-如何保证传输可靠性
转自 https://blog.csdn.net/xuzhangze/article/details/80490362 TCP协议保证数据传输可靠性的方式主要有: (1)检验和 在发送数据时,为了计算 ...
- (6.2)vim文本编辑器
vi / vim是Unix / Linux上最常用的文本编辑器而且功能非常强大. vim文本编辑器只有命令,没有菜单.