basic _ string& append( size _ type _Count , value _ type _Ch );
string str1e ( "Hello " );
str1e.append ( 4 , '!' ); // s1= ” Hello !!!! ”
basic_string::assign
给string 赋值。 (比“=”更灵活)
(1) 向string 赋C-string
basic _ string& assign( const value _ type* _Ptr );
string s;
const char *c = "Out There";
s.assign ( c ); // s= ” Out There ”
(2) 向string 赋C-string 的一部分
basic _ string& assign( const value _ type* _Ptr , size _ type _Count );
string s;
const char *c = "Out There";
s.assign ( c , 3 ); // s= ” Out ”
(3) 向string 赋string(有两种方法)
basic _ string& assign( const basic _ string& _Str );
string s1 ( "Hello" ), s2 ( "Wide" ), s3( "World" );
s1.assign ( s2 ); // s1= ” Wide ”
s1 = s3; // s1= ” World ”
(4) 向string 赋string 的一部分 ---A
basic _ string& assign( const basic _ string& _Str , size _ type off ,
size _ type _Count );
string s1 ( "Hello " ), s2 ( "Wide World " );
s1.assign ( s2 , 5 , 5 ); // s1= ” Hello World ”
(5) 向string 赋string 的一部分 ---B
template<class InIt> basic _ string& assign(
InputIterator _First ,
InputIterator _Last );
string str1f ( "Hello " ), str2f ( "Wide World" );
str1f.assign ( str2f.begin ( ) + 5 , str2f.end ( ) ); // s1= ” Wide World ”
(6) 向string 赋 多个字符
basic _ string& assign( size _ type _Count , value _ type _Ch );
string str1e ( "Hello " );
str1e.assign ( 4 , '!' ); // s1= ” !!!! ”
C++中String类的用法(二)
basic_string::compare
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-34906-13.html
中国大地思想的大旗又高高举起和飘扬了
我们也要摆出姿态