目录
访问:
下标
但是中文会bug
迭代器.
迭代器遍历
zhonwenbug:
操作:加
+:"abc"+"d"="abcd"
比较大小(字典序)==<=!=
字符串长度:.length()或者。size(一样)
插入insert(***):
str.insert(num,str2)
在str的位置为num插入str
str2.insert(it,it1,it2)
在it(迭代器)位置插入【左闭右开】it1-it2(迭代器)的字符串
删除erase()
erase(迭代器)【点删除】
erase(迭代器,迭代器) 【区间删除】左闭右开
erase(数字1,数字2)
删除1处向后2长度的字符串
清空clear()
取子串substr(pos,len)
返回值:从pos位置起,长度为len的子串
寻找子串是否存在.find()
str.find(str2)
str.find(str2,pos):pos(index数字)开始,是否存在
返回值:
存在:返回位置坐标
不存在:返回string::npos
替换replace(pos,len,str)
把pos位置(号位index),长度为len的子串删除,然后在pos位置插入str。
也可以使用迭代器代替pos&len:
replace(it1,it2,str),表示从it1到it2之间的删除。
∴len不一定等于str长度
【存档()】
#include <cstdio>
#include <queue>
#include <vector>
#include <set>
#include <string>
#include <iostream>
#include <map>
using namespace std;
const int MAXN = 100000;
set<int> st;
string str1,str2;
map<char,int> mp;
int main()
{
mp['#']=3;
mp['a']=4;
mp['A']=5;
str1="yhl! hello hell";str2="c4bomb";
str1.replace(5,5,str2);
//str1.replace(str1.begin() ,str1.end()-1 ,str2);
for(int i=0; i<str1.size() ;i++)
cout<<i<<":"<<str1[i]<<"\n";
cout<<str1.find("hell",6)<<"是否存在";
//str1.insert(2,str2);
//cout<<(string::npos)<<"#";
str1.erase(1,2);
cout<<str1.length();
for(string::iterator its=str1.begin();its!=str1.end();its++)
cout<<*its<<"()";
set<int>::iterator it;
it=st.begin();
for(it=st.begin() ;it!=st.end();it++)
printf("%d ",*it);
printf("size:%d\n",st.size() );
it=st.find(1);
set<int>::iterator it2;
it2=st.find(3);
it2++;
//st.erase(4);
st.erase(it,it2);
for(it=st.begin() ;it!=st.end();it++)
printf("%d ",*it);
}