STL笔记

string

插入insert

s.insert(1,"sdfsdf");
s.insert(1,s2);
s.insert(5,3,"ds");

求子串substr

s2=s.substr(2,4);
s2=s.substr(2);

删除字串erase

s.erase(2,4);
s.erase(5);//删除5及以后的字符

查找字符串find

pos=s.find("key");//s中第一次出现匹配子串的位置
pos2=s.find("key",10);//s中从第10位开始第一次出现匹配子串的位置
//匹配结果为空时,返回尾地址后一个地址

排序sort

sort(s.begin(),s.end());

下一个全排列

next_permutation(s.begin(),s.end());

字符数组匹配strcmp

strcmp(c,"hello world!");//相同返回0,不同返回1;

迭代器iterator

循环

for(iter=s.begin();iter!=s.end();iter++);

map

map按第一关键字排序。
查找,计数(只会返回0或1),删除只能依据第一关键字。
用insert插入时,插入的是一个pair

二分查找

val是否出现在闭区间中,返回0或1

binary_search(first,last,val)

有序数列中第一个“大于等于”val的元素的位置(返回值为地址)

lower_bound(first,last,val);

有序数列中第一个“大于”val的元素的位置(返回值为地址)

upper_bound(first,last,val);

https://blog.csdn.net/Gh0st_Lx/article/details/122851588

posted @ 2022-02-06 00:02  xyc1719  阅读(28)  评论(0)    收藏  举报