2016/05/06
来源:互联网 发布:上瘾网络剧幕后花絮 编辑:程序博客网 时间:2024/05/19 16:03
<span style="font-family: Arial, Helvetica, sans-serif;">常用STL:</span>
<pre code_snippet_id="1674595" snippet_file_name="blog_20160506_1_9718887" name="code" class="cpp"><span></span>vector:动态数组,头文件 #include <vector>
<span style="white-space:pre"></span>定义:vector<type> vec_name;//定义整形vectorvector<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], 长度为_countstring 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:集合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:浮点数绝对值函数
0 0
- 2016/05/06
- 2016/05/06
- 2016-05-06安卓之Activity
- [心得]——2016-05-06
- 06/05/2016引用变量、指针升级
- 06/05/2016运算符重载
- [2016/06/27] LeetCode / Java - Day 05 -
- [2016-05-06]CSS之float详解
- 06/05/2016函数参数传递探究升级
- 05-06
- 2016-06
- 2016-06-06-1
- 2016/06/06
- 2016CCPC东北地区大学生程序设计竞赛【01/03/05/06/08】
- 05-04-06
- 05/06/29
- 05/06/30
- 05/07/06
- python中write没有写入是什么情况
- 使用Eclipse Memory Analyzer进行内存泄漏分析三部曲
- video标签播放视频,有声音无图像的解决办法
- 从此不求人:自主研发一套PHP前端开发框架(31)搭建后台框架
- ArcGIS教程:控制图表的轴
- 2016/05/06
- Android Dev Intro - Android Looper And Handler
- POJ 3522 Slim Span【枚举+克鲁斯卡尔求最小生成树】
- Linux命令
- 51nod-1040-最大公约数之和(欧拉函数)
- SpringMvc初步学习
- php在windows server 2012的iis8下面的安装
- ZooKeeper原理及使用
- Android字符串相关类 - CharSequence