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> ...
随机推荐
- 7.STM32中GPIO理解
端口概述 在STM32中,每个I/O端口可以由软件配置成为输入/输出模式.复位期间或刚复位后,I/O端口被配置成浮空输入模式.所有的GPIO引脚有一个内部弱上拉和弱下拉,当配置为输入时, 它们可以被激 ...
- awesome资源包
.NET资源包 https://github.com/jobbole/awesome-dotnet-cn java资源包 https://github.com/jobbole/awesome-java ...
- idea中使用MyBatis Generator
1.新建maven项目 2.新建Generator配置文件 generator_config.xml <?xml version="1.0" encoding="U ...
- C#windows桌面应用小程序制作——大文件数据分段解析存储
现在的任务就是做一个大文件解析的桌面应用小程序,具体需求就是:将一个很大的文件里的数据按一定标志拆分然后分别保存到某个文件夹下面. 解析的文件内容为以下内容: windows 应用小程序界面 具体代码 ...
- flask+redis实现抢购(秒杀)功能
今天面试了 一家非常高大上的公司,问了我关于redis的实用性问题,但是答的不是很好,所以下午通过再次学习 redis,实现相关实用性功能的一种. 对于抢购功能,难点在于 抢购时 由于高并发请求,导致 ...
- Django基础回顾与补充(79-80)
Django框架之回顾与补充(d79-80)一 HTTP协议:(重点) 1 请求 -请求首行 -GET /index HTTP/1.1 -请求头部(在django框架中,可以从META ...
- golang 统计uint64 数字二进制存储中1的数量
package main import ( "fmt") // pc[i] is the population count of i.var pc [256]byte fun ...
- Android 开发 关于7.0 FileUriExposedException异常 详解
异常原因 Android不再允许在app中把file://Uri暴露给其他app,包括但不局限于通过Intent或ClipData 等方法.原因在于使用file://Uri会有一些风险,比如: 文件是 ...
- @Override is not allowed when implementing interface method
使用idea导入maven项目时 会出现如下报错 @Override从jdk1.5开始出现的,是用来标注方法重写:通常方法重写发生在继承父类,重写父类方法,或者实现接口,实现接口方法: @Overri ...
- Anatomy of a Database System学习笔记 - 查询
查询解析 解析会生成一个查询的内部展示.格式检查包含在解析过程中. 每次解析一个SELECT,步骤如下:1. 从FROM里找到表名,转换成schema.tablename.这一步需要调用目录管理器ca ...