c++语言知识点CPPstring

c++语言知识点CPPstring

ID:38796783

大小:163.00 KB

页数:26页

时间:2019-06-19

c++语言知识点CPPstring_第1页
c++语言知识点CPPstring_第2页
c++语言知识点CPPstring_第3页
c++语言知识点CPPstring_第4页
c++语言知识点CPPstring_第5页
资源描述:

《c++语言知识点CPPstring》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、std::stringStringinC++StandardLibrarystd::stringConstructor构造函数Assign赋值Append附加Insert插入Concatenate拼接Substring子串Erase删除Replace替换Compare比较Size大小Elements元素Find查找ToCstringC风格串Swap交换I/O输入输出1.Constructorstring()string(s)string(s,pos,n)string(p)string(p,n)string(n,c)2.Assignx.assign(s)x.assign(s,pos,n

2、)x.assign(p)x.assign(p,n)x.assign(n,c)x=sx=px=c3.Appendx.append(s)x.append(s,pos,n)x.append(p)x.append(p,n)x.append(n,c)x+=sx+=px+=c4.Insertx.insert(pos,s)x.insert(pos,s,pos2,n)x.insert(pos,p)x.insert(pos,p,n)x.insert(pos,n,c)5.Concatenatex+sx+pp+xx+cc+x6.Substringx.substr(pos=0,n=npos)NOTE:std

3、::string::npos表示串中字符的最大位置i.e.x.substr(pos,n)x.substr(pos)x.substr()stringx=“abcdef”;x.substr(2,3);//”cde”x.substr(2,100);//”cdef”x.substr(2);//“cdef”x.substr();//“abcdef”7.Erasex.erase(pos=0,n=npos)x.clear()i.e.x.erase(pos,n)x.erase(pos)x.erase()i.e.x.clear()8.Replacex.replace(pos,n,s)x.replace

4、(pos,n,s,pos2,n2)x.replace(pos,n,p)x.replace(pos,n,p,n2)x.replace(pos,n,n2,c)9.Comparex.compare(s)x.compare(p)x.compare(pos,n,s)x.compare(pos,n,s,pos2,n2)x.compare(pos,n,p,n2=npos)==!=<<=>>=0+-truefalseExamplex==sx==pp==x10.Sizex.size()x.length()x.empty()11.Elementsx[i]x.at(i)Examplex[i]=c;x.at

5、(i)=c;std::cout<>x[i];12.Findfindrfindfind_first_offind_last_offind_first_not_offind_last_not_ofx.find(s,i=0)x.find(p,i=0)x.find(p,i,n)x.find(c,i=0)findExamplex.find(s);x.find(s,i);rfindx.rfind(s,i=npos)x.rfind(p,i=npos)x.rfind(p,i,n)x.rfind(c,i=npos)Examplex.rfind(s);x.rfind(s,i

6、);find_first_ofx.find_first_of(s,i=0)x.find_first_of(p,i=0)x.find_first_of(p,i,n)x.find_first_of(c,i=0)find_last_ofx.find_last_of(s,i=npos)x.find_last_of(p,i=npos)x.find_last_of(p,i,n)x.find_last_of(c,i=npos)find_first_not_ofx.find_first_not_of(s,i=0)x.find_first_not_of(p,i=0)x.find_first_not_o

7、f(p,i,n)x.find_first_not_of(c,i=0)find_last_not_ofx.find_last_not_of(s,i=npos)x.find_last_not_of(p,i=npos)x.find_last_not_of(p,i,n)x.find_last_not_of(c,i=npos)Usageoffind返回值类型string::size_type返回值找到:返回匹配位置找不到:返回nposExample:string::

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。