欢迎来到天天文库
浏览记录
ID:42651224
大小:256.00 KB
页数:12页
时间:2019-09-19
《字符串类和标准输入输出流类专题讲座》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、标准模板库STL——字符串类和标准输入输出流类简介一、C++中的字符串string1、string是模板类basic_string的char型版本或者说模板类basic_string的实例化。namespacestd{template,classAllocator=allocator>classbasic_string;}namespacestd{typedefbasic_stringstring;typedefbasic_stri
2、ngwstring;}2、string的成员函数OperationEffectconstructorsCreateorcopyastringdestructorDestroysastring=,assign()Assignanewvalueswap()Swapsvaluesbetweentwostrings+=,append(),push_back()Appendcharactersinsert()Insertscharacterserase()Deletescharactersclear()Removesallchara
3、cters(makesitempty)resize()Changesthenumberofcharacters(deletesorappendscharactersattheend)replace()Replacescharacters+Concatenatesstrings==,!=,<,<=,>,>=,compare()Comparestringssize(),length()Returnthenumberofcharactersmax_size()Returnsthemaximumpossiblenumberofcharacterse
4、mpty()Returnswhetherthestringisemptycapacity()Returnsthenumberofcharactersthatcanheldwithoutbereallocation[],at()Accessacharacter>>,getline()Readthevaluefromastream<5、邓涛2006年8月82data()Returnsthevalueascharacterarraysubstr()ReturnsacertainsubstringfindfunctionsSearchforacertainsubstringorcharacter(有多种不同形式的查找,故有多个查找函数)begin(),end()Providenormaliteratorsupportrbegin(),rend()Providereverseiteratorsupport注:string的许多成员函数都有许多不同的版本(即参数的个数、类型有差别6、)。如构造函数string就有如下多种:stringsCreatestheemptystringsstrings(str)Createsastringasacopyoftheexistingstringstrstrings(str,stridx)Createsastringsthatisinitializedbythecharactersofstringstrstartingwithindexstridxstrings(str,stridx,strlen)Createsastringsthatisinitializedby,atmost,s7、trlencharactersofstringstrstartingwithindexstridxstrings(cstr)CreatesastringsthatisinitializedbytheC-stringcstrstrings(chars,chars_len)Createsastringsthatisinitializedbychars_lencharactersofthecharacterarraycharsstrings(num,c)Createsastringthathasnumoccurrencesofcharacterc8、strings(beg,end)Createsastringthatisinitializedbyallcharactersoftherange[beg,end)s.~strin
5、邓涛2006年8月82data()Returnsthevalueascharacterarraysubstr()ReturnsacertainsubstringfindfunctionsSearchforacertainsubstringorcharacter(有多种不同形式的查找,故有多个查找函数)begin(),end()Providenormaliteratorsupportrbegin(),rend()Providereverseiteratorsupport注:string的许多成员函数都有许多不同的版本(即参数的个数、类型有差别
6、)。如构造函数string就有如下多种:stringsCreatestheemptystringsstrings(str)Createsastringasacopyoftheexistingstringstrstrings(str,stridx)Createsastringsthatisinitializedbythecharactersofstringstrstartingwithindexstridxstrings(str,stridx,strlen)Createsastringsthatisinitializedby,atmost,s
7、trlencharactersofstringstrstartingwithindexstridxstrings(cstr)CreatesastringsthatisinitializedbytheC-stringcstrstrings(chars,chars_len)Createsastringsthatisinitializedbychars_lencharactersofthecharacterarraycharsstrings(num,c)Createsastringthathasnumoccurrencesofcharacterc
8、strings(beg,end)Createsastringthatisinitializedbyallcharactersoftherange[beg,end)s.~strin
此文档下载收益归作者所有