c++ stl常用
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<iterator>
#include<map>
#include<fstream>
#include <string>
#include <hash_map>
using namespace std;
int main()
{
/* //vector have not push_front
vector<string> vstr(10,"str");
vector<string>::iterator itvs=vstr.begin();
vstr.push_back("lll");
vstr.push_back("dddddd");
vstr.pop_back();
for(itvs=vstr.begin(); itvs!=vstr.end(); itvs++)
{
cout<<*itvs<<"***";
}
cout<<vstr.back()<<vstr.size()<<vstr.front()<<endl;
//list
list<string> slist;
slist.push_back("aaa");
slist.push_back("hhh");
slist.push_front("***");
list<string>::iterator it=slist.begin();
slist.insert(it,"front");
for(it=slist.begin(); it!=slist.end(); it++)
{
cout<<*it<<"___";
}
cout<<endl;
slist.sort();
slist.erase(--it);//it 指向最后一个元素的下一个元素
for(it=slist.begin(); it!=slist.end(); it++)
{
cout<<*it<<"___";
}
//map
map<string,int> one;
one["the"]=3;
one.insert(map<string ,int>::value_type("as",2));/////!!!注意格式
map<string ,int>::iterator itmap=one.begin();
cout<<itmap->first<<":";
cout<<itmap->second;
one.erase("the");
ifstream in("in.txt");
string word;
//统计单词个数
while(in>>word){
one[word]+=1;
}
for(itmap=one.begin();itmap!=one.end();itmap++)
{
cout<<itmap->first<<":"<<itmap->second<<endl;
}
//set have not push pop
set<int> a;
a.insert(19);
a.clear();
cout<<a.count(0);//统计指定键的个数
for(int i=0;i<10;i++)
{
a.insert(i);
}
//集合无序,没有sort,映射也没有sort*/
/////////////以下编译不通过
hash_map<int, string> mp;
mp[9527] = "唐伯虎点秋香";
mp[10000] = "百万富翁的生活";
mp[88888] = "白领的工资底线";
if(mp.find(10000) != mp.end())
{
cout<<"lll" <<end;//....
}
}
c++ stl常用的更多相关文章
- C++ STL 常用算术和生成算法
C++ STL 常用算术和生成算法 accumulate() accumulate: 对指定范围内的元素求和,然后结果再加上一个由val指定的初始值. #include<numeric> ...
- C++ STL 常用拷贝和替换算法
C++ STL 常用拷贝和替换算法 copy() 复制 vector<int> vecIntA; vecIntA.push_back(1); vecIntA.push_back(3); v ...
- C++ STL 常用排序算法
C++ STL 常用排序算法 merge() 以下是排序和通用算法:提供元素排序策略 merge: 合并两个有序序列,存放到另一个序列. 例如: vecIntA,vecIntB,vecIntC是用ve ...
- C++ STL 常用查找算法
C++ STL 常用查找算法 adjacent_find() 在iterator对标识元素范围内,查找一对相邻重复元素,找到则返回指向这对元素的第一个元素的迭代器.否则返回past-the-end. ...
- C++ STL 常用遍历算法
C++ STL 常用遍历算法 STL的容器算法迭代器的设计理念 1) STL的容器通过类模板技术,实现数据类型和容器模型的分离 2) STL的迭代器技术实现了遍历容器的统一方法:也为STL的算法提供了 ...
- STL常用结构与方法简明总结
C++常用的数据结构 序列式容器 vector(向量.有序数列),list(双向链表),deque(双端队列) 适配器容器 stack(栈),queue(队列) 关联式容器 map(映射.键值对二叉树 ...
- STL常用序列容器
这里简要的记述一下STL常用容器的实现原理,要点等内容. vector vector是比较常用的stl容器,用法与数组是非类似,其内部实现是连续空间分配,与数组的不同之处在于可弹性增加空间,而arra ...
- C++STL 常用 函数 用法
学完c++快一年了,感觉很有遗憾,因为一直没有感觉到c++的强大之处,当时最大的感觉就是这个东西的输入输出比C语言要简单好写. 后来我发现了qt,opencv,opengl,原来,c++好玩的狠. 在 ...
- C++中STL常用容器的优点和缺点
我们常用到的STL容器有vector.list.deque.map.multimap.set和multiset,它们究竟有何区别,各自的优缺点是什么,为了更好的扬长避短,提高程序性能,在使用之前需要我 ...
- C++ STL常用容器浅析
首先要理解什么是容器,在C++中容器被定义为:在数据存储上,有一种对象类型,它可以持有其它对象或指向其它对象的指针,这种对象类型就叫做容器.简单来说 容器就是包含其他类的对象们的对象,当然这种(容器) ...
随机推荐
- javascript对象讲解
js的数据类型 基本数据类型:string undefined null boolean number 引用数据类型:object 二者的区别: 基本数据类型就是简单的赋值,引用数据 ...
- 1044 Shopping in Mars (25 分)
1044 Shopping in Mars (25 分) Shopping in Mars is quite a different experience. The Mars people pay b ...
- 在ie6下的png图片的兼容问题
png图片在ie6下是这样的: 正确样式: 这样解决: html代码: <body> <div class="gys"></div> </ ...
- python3 string
字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可.例如: var1 = 'Hello World!' var2 ...
- ubuntu 命令汇总
1.linux添加全局变量 //查看当前的全局变量 echo $PATH //打开bashrc 文件,在最后面添加需要 加入的目录路径 vi ~/.bashrc //例如: export PATH=$ ...
- spring boot + jpa + kotlin入门实例
spring boot +jpa的文章网络上已经有不少,这里主要补充一下用kotlin来做. kotlin里面的data class来创建entity可以帮助我们减少不少的代码,比如现在这个User的 ...
- uva-10305-水题-拓扑排序
输入n,m,n代表点数,m代表边数(i,j),排序时i在j前面,没出现的点随意排 #include <iostream> #include<stdio.h> #include& ...
- jar包双击执行引用外部包问题
大家都知道一个java应用项目可以打包成一个jar,当然你必须指定一个拥有main函数的main class作为你这个jar包的程序入口. 具体的方法是修改jar包内目录META-INF下的MANIF ...
- windows的类似shell 命令操作
一,类似linux的grep命令 参考网站:https://www.cnblogs.com/zxy1992/p/4372717.html windows执行cmd命令查找sql进程: C:\Users ...
- 3.Web项目中使用Log4j实例
转自:https://blog.csdn.net/luohai859/article/details/52250807 上面代码描述了Log4j的简单应用,其实使用Log4j也就是这样简单方便.当然除 ...