轉載地址:http://blog.csdn.net/u010300792/article/details/30215897
append函數是向string 的後面追加字符或字符串。
(1)向string 的後面加C-string
1
2
3
4
|
basic_string& append( const value_type* _Ptr ); string s ( "Hello " ); // s=”Hello ” const char *c = "Out There " ; s.append ( c ); // s=”Hello Out There” |
(2)向string 的後面加C-string 的一部分
1
2
3
4
|
basic_string& append( const value_type* _Ptr, size_type _Count ); string s ( "Hello " ); // s=”Hello ” const char *c = "Out There " ; s.append ( c , 3 ); // s=”Hello Out” |
(3)向string 的後面加string(有兩種方法)
1
2
3
4
|
basic_string& append( const basic_string& _Str ); string s1 ( "Hello " ), s2 ( "Wide " ), s3( "World " ); s1.append ( s2 ); // s1=”Hello Wide” s1 += s3; // s1=”Hello Wide World” |
(4)向string 的後面加string 的一部分 ---A
1
2
3
4
|
basic_string& append( const basic_string& _Str, size_type _Off, size_type _Count ); string s1 ( "Hello " ), s2 ( "Wide World " ); s1.append ( s2 , 5 , 5 ); // s1=”Hello World” |
(5)向string 的後面加string 的一部分 ---B
1
2
3
4
5
|
template < class InputIterator> basic_string& append( InputIterator _First, InputIterator _Last ); string str1f ( "Hello " ), str2f ( "Wide World" ); str1f.append ( str2f.begin ( ) + 5 , str2f.end ( ) ); // s1=”Hello World” |
(6)向string 的後面加多個字符
1
2
3
|
basic_string& append( size_type _Count, value_type _Ch ); string str1e ( "Hello " ); str1e.append ( 4 , '!' ); // s1=”Hello !!!!” |