C ++でappendを使用する方法
前書き
C ++での追記機能のための文字列型の列の後ろに付加した文字または文字列
一般的な使用法
1)文字列の後ろにC文字列を追加します
string s = "hello"; const char * c = "out here";
s.append(c); // c型の文字列sを現在の文字列
の末尾に接続しますs = "hello out here";
2)文字列の後ろにC文字列の一部を追加します
string s =” hello”; const char * c =“ out here”;
s.append(c、3); // c型文字列sの最初のn文字を現在の文字列
の末尾に接続しますs =“ helloアウト ";
3)文字列の後ろに文字列を追加します
string s1 = "hello"; string s2 = "wide"; string s3 = "world";
s1.append(s2); s1 + = s3; //文字列sを現在の文字列の末尾に接続します
s1 = "helloワイド "; s1 ="こんにちはワイドワールド ";
4)文字列の一部を文字列の後ろに追加します
string s1 = "hello"、s2 = "wide world";
s1.append(s2、5、5);文字列s2の5から始まる5文字を現在の文字列の終わりに接続します
s1 = "hello world";
string str1 = "hello"、str2 = "wide world";
str1.append(str2.begin()+ 5、str2.end()); // s2 begin()+ 5とend()のイテレーターを配置します。現在の文字列の末尾に接続されています
str1 = "hello world";
5)文字列に複数の文字を追加します
string s1 = "hello";
s1.append(4、 '!'); //現在の文字列の末尾に4文字を追加します!
s1 = "hello !!!";