容器之vector
2024-08-26 08:54:12
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std;
int main(){
vector <int>obj;//创建一个向量存储容器
for(int i=;i<;i++)
{
obj.push_back(i); //在vector尾部加入一个数据 string中的push_back表示在字符串之后插入一个字符
cout<<obj[i]<<",";
}
cout<<"\n"<<endl;
for(int i=;i<;i++)
{
obj.pop_back(); //去掉数组最后一个数据
}
for(int i=;i<obj.size();i++)//size() 容器中实际数据个数
{
cout<<obj[i]<<",";
}
cout<<"\n"<<endl;
/*obj.clear();//清除容器中的数据
for(int i=0;i<obj.size();i++)//size() 容器中实际数据个数
{
cout<<obj[i]<<",";
}*/
sort(obj.begin(),obj.end());//从小到大排序
for(int i=;i<obj.size();i++)//size() 容器中实际数据个数
{
cout<<obj[i]<<",";
}
cout<<"\n"<<endl;
reverse(obj.begin(),obj.end());//从大到小
for(int i=;i<obj.size();i++)//size() 容器中实际数据个数
{
cout<<obj[i]<<",";
}
system("pause");
return ;
}
最新文章
- iOS应用程序的生命周期
- flex-布局,轻松制作移动端网页
- CSS层叠
- C#操作文件夹及文件的方法的使用
- DP:Corn Fields(POJ 3254)
- unity, 由unity5.2.1升级到5.4.2物体变亮解法
- UI1_Calayer
- ArcEngine做栅格数据拉伸
- Python学习笔记12:标准库之对象序列化(pickle包,cPickle包)
- 关于No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=armv7 armv7s)使用百度地图的解决办法
- EL表达式的简单实用
- EasyUI的Datagrid鼠标悬停显示单元格内容
- word文档转pdf,支持.doc和.docx,另附抽取pdf指定页数的方法
- java打包发布程序.jar(Eclipse)
- oracle表分区创建
- ssh agent-forward
- SpringMVC 处理Date类型数据@InitBinder @DateTimeFormat 注解 的使用
- 【BZOJ2820】ygy的gcd
- 线程【五】VCL下的线程类
- shell脚本中对简单实现对log的处理
热门文章
- android 长按弹出菜单,复制,粘贴,全选
- Go -- RPC 之 Thrift
- flask的debug模式下,网页输入pin码进行调试
- 深入理解javascript之设计模式
- BubbleGum96 开箱杂谈与软件资源
- GridView的经常使用属性
- Android开发的环境搭建及HelloWorld的实现
- val();html();.text()区别 setInterval与setTimeout的区别
- openwrt procd 运行的一些log
- u-boot简单学习笔记(二)——AR9331 uboot.lds分析