2016/05/06
2016-05-06 14:52
218 查看
常用STL:
//vector:动态数组,头文件 #include <vector>
//定义:vector<type> vec_name;
//定义整形vector
vector<int> a;
//向容器末尾动态添加元素
a.push_back(1);
a.push_back(2);
//返回元素个数
int n = a.size();
//遍历容器
for(int i=0; i<n; i++)
{
cout<<a[i]<<endl;
}
a.clear();
//string:字符串容器 头文件#include <string>
//定义
string str, str1 = "cd";
//向末尾添加字符元素
str.push_back('a');
char c = 'b';
str += c;
str += str1;
//输出与遍历
cout<<str<<endl;
int n = str.size();
for(int i=0; i<n; i++)
{
cout<<str[i]<<endl;
}
//sub返回str的一个子串, 起始位置为str[_off], 长度为_count
string sub = str.substr(_off, _count);
str.clear();
//queue:队列 头文件 #include <queue>
//queue<type> Q;
queue<int> Q;
Q.push(1);
Q.push(2);
int n = Q.size();
while(Q.size() > 0)
{
cout<<Q.front();
Q.pop();
}
//stack:栈 头文件 #include<stack>
stack<int> S:
S.push(1);
S.push(2);
while(!S.empty())
{
cout<<S.top()<<endl;;
S.pop();
}
//set:集合 头文件 #include<set>
set<int> S;
S.insert(1);
S.insert(2);
S.erase(1);
int _count = S.count(2);
S.clear();
//map:键值映射容器 头文件:#include <map>
map<int, int> M;
M[1] = 1;
M[2] = 2;
cout<<M[1]<<' '<<M[2]<<endl;
M.clear();
库函数:
常用函数库:#include <algorithm> #include<cstdlib> #include <math.h>
常用函数:
排序函数sort:
//int a[100]; vector<int> vec;
sort(a, a+100);
sort(vec.begin(), vec.end());
二分查找函数:
//vector<int> vec
//以int型容器为例,idx返回vec中第一个大于等于x的元素的下标
//idx2返回vec中第一个大于x元素的下标
int idx = lower_bound(vec.begin(), vec.end(), x) - vec.begin();
int idx2 = upper_bound(vec.begin(), vec.end(), x) - vec.begin();
数学函数:
pow:幂函数
sqrt:根号函数
abs:绝对值函数
fabs:浮点数绝对值函数
//vector:动态数组,头文件 #include <vector>
//定义:vector<type> vec_name;
//定义整形vector
vector<int> a;
//向容器末尾动态添加元素
a.push_back(1);
a.push_back(2);
//返回元素个数
int n = a.size();
//遍历容器
for(int i=0; i<n; i++)
{
cout<<a[i]<<endl;
}
a.clear();
//string:字符串容器 头文件#include <string>
//定义
string str, str1 = "cd";
//向末尾添加字符元素
str.push_back('a');
char c = 'b';
str += c;
str += str1;
//输出与遍历
cout<<str<<endl;
int n = str.size();
for(int i=0; i<n; i++)
{
cout<<str[i]<<endl;
}
//sub返回str的一个子串, 起始位置为str[_off], 长度为_count
string sub = str.substr(_off, _count);
str.clear();
//queue:队列 头文件 #include <queue>
//queue<type> Q;
queue<int> Q;
Q.push(1);
Q.push(2);
int n = Q.size();
while(Q.size() > 0)
{
cout<<Q.front();
Q.pop();
}
//stack:栈 头文件 #include<stack>
stack<int> S:
S.push(1);
S.push(2);
while(!S.empty())
{
cout<<S.top()<<endl;;
S.pop();
}
//set:集合 头文件 #include<set>
set<int> S;
S.insert(1);
S.insert(2);
S.erase(1);
int _count = S.count(2);
S.clear();
//map:键值映射容器 头文件:#include <map>
map<int, int> M;
M[1] = 1;
M[2] = 2;
cout<<M[1]<<' '<<M[2]<<endl;
M.clear();
库函数:
常用函数库:#include <algorithm> #include<cstdlib> #include <math.h>
常用函数:
排序函数sort:
//int a[100]; vector<int> vec;
sort(a, a+100);
sort(vec.begin(), vec.end());
二分查找函数:
//vector<int> vec
//以int型容器为例,idx返回vec中第一个大于等于x的元素的下标
//idx2返回vec中第一个大于x元素的下标
int idx = lower_bound(vec.begin(), vec.end(), x) - vec.begin();
int idx2 = upper_bound(vec.begin(), vec.end(), x) - vec.begin();
数学函数:
pow:幂函数
sqrt:根号函数
abs:绝对值函数
fabs:浮点数绝对值函数
相关文章推荐
- React表单组建
- Android Studio上打的包在arm64位机器上找不到对应的so库
- 快速使用Bootstrap搭建传送带
- Mybaits---关于关联表数据查询
- Android Dev Intro - Thread Looper and Handler
- 大数据学习资源汇总
- 的确,Java存在缺陷。但是……
- 正则表达式判断连续号码
- easyUi 无限极分类
- python: 知乎大规模(34k)用户爬虫
- HDOJ题目分类
- 在Android开发中使用ORMLite--篇一
- ButterKnife--View注入框架---懒人必备
- 设计模式之观察者模式
- Mysql安装时出现APPLY security settings错误
- 一个苹果证书怎么多次使用(授权Mac开发)——导出p12文件
- Windows bat with adb
- 汇编学习第三课之if/if...else语句分析
- MySQL 子查询 EXISTS 和 NOT EXISTS
- 无线篇(5.2) 01. FortiAP 安装与配置 ❀ 飞塔 (Fortinet) 防火墙