
STL模板
策马奔腾向前冲
这个作者很懒,什么都没留下…
展开
-
set与multiset
#include <iostream>#include <set>using namespace std;struct node{ int x, y; bool operator< (const node& other)const { //if(x != other.x) return x < other.x; }};int main(){ set<node>s; s..原创 2021-03-04 13:35:16 · 214 阅读 · 1 评论 -
C++list常用操作
一、List定义list是stl实现的双向链表,与向量(vector),它允许快速的插入和删除,但是随即访问却比较慢。使用时需添加头文件#include <list>二、List定义和初始化list<int>lst;//创建空listlist<int>lst(5);list<int>lst(3,2);//创建含有3个元素的l...原创 2019-08-18 19:17:02 · 389 阅读 · 0 评论 -
STL之find()
1.find()函数的调用形式为 find(start,end,value)start搜寻的起点,end搜寻的终点,要寻找的value值容器的表示方法:find(a.begin(),a.end(),value)数组的表示方法:find(a,a+length,value)所有的返回,均是迭代器(容器)或指针(数组),而非是直观感觉上的索引下标。如果在查找范围内不存在,返回a.en...原创 2018-12-30 09:56:05 · 2628 阅读 · 0 评论 -
STL模板之自定义排序
set集合,priority_queue优先队列,map都可以自定义排序方法其共性就是定义一个结构体,然后在其内部重写operator()函数,提供比较规则,另外传入的参数类型要模板内部的参数类型一致struct cmp{ bool operator() (const 类型& a,const 类型& b)const { return a&...原创 2018-12-30 09:36:06 · 281 阅读 · 0 评论 -
vector常见用法
vector定义二维数组vector<vector<int> >v(m,vector<int>(n));vector<vector<int> >v(N); 第一维大小确定,第二维大小不确定。vector<vector<int> >v;可使用v.resize()改变一维的大小int in[N],n=2...原创 2019-07-16 13:43:51 · 1141 阅读 · 0 评论 -
C++正则表达式
三个基本操作1.regex_match判断目标字串是否匹配指定的正则表达式2.regex_search在目标字串中寻找匹配指定正则式的字串3.regex_replace在目标字串中寻找匹配指定正则式的字串,之后用预设的字串替换这些匹配的字串每次匹配应该包含三个主要元素,1)目标字串 2)正则式 3)匹配结果正则表达式示例表字 符 意 义 示 例* 任意长度的字符串。 a...原创 2019-04-01 19:04:06 · 727 阅读 · 0 评论 -
C++ string类insert函数
string的成员函数insert有以下多种重载:string &insert(int p0, const char *s);——在p0位置插入字符串sstring &insert(int p0, const char *s, int n);——在p0位置插入字符串s的前n个字符string &insert(int p0,const string &s)...转载 2019-02-25 15:36:41 · 5898 阅读 · 1 评论