「cpp/string/basic string/append」の版間の差分
提供: cppreference.com
< cpp | string | basic string
細 (1版:Import from Dokuwiki) |
細 (文字列「<code terminal>」を「<syntaxhighlight lang="text">」に置換) |
||
30行: | 30行: | ||
出力: | 出力: | ||
− | < | + | <> |
Hello World!!!!!!!!!! | Hello World!!!!!!!!!! | ||
</syntaxhighlight> | </syntaxhighlight> | ||
46行: | 46行: | ||
実行すると次の出力になります。 | 実行すると次の出力になります。 | ||
− | < | + | <> |
str1 is Eventually I stopped caring... nobody noticed. | str1 is Eventually I stopped caring... nobody noticed. | ||
</syntaxhighlight> | </syntaxhighlight> |
2012年5月2日 (水) 03:40時点における版
Syntax:
#include <string> string& append( const string& str ); string& append( const charT* str ); string& append( const string& str, size_type index, size_type len ); string& append( const charT* str, size_type num ); string& append( size_type num, charT ch ); string& append( input_iterator start, input_iterator end );
append()関数は、以下のいずれかの動作をします。
- (1,2番目) "str"を文字列の最後に追加します。
- (3番目) "str"の"index"から始まり長さ"len"の部分文字列を文字列の最後に追加します。
- (4番目) "str"から"num"数の文字を文字列の最後に追加します。
- (5番目) 文字"ch"を"num"分繰り返し、文字列の最後に追加します。
- (6番目) イテレータ"start"から"end"までを文字列の最後に追加します。
たとえば、次のコードは、文字列に"!"を10個コピーして追加するために、append()を使っています。
string str = "Hello World"; str.append( 10, '!' ); cout << str << endl;
出力:
Hello World!!!!!!!!!!
次の例は、文字列と別の文字列の一部をつなぎ合わせるために、append()を使っています。
string str1 = "Eventually I stopped caring... "; string str2 = "but that was the '80s so nobody noticed."; str1.append( str2, 25, 15 ); cout << "str1 is " << str1 << endl;
実行すると次の出力になります。
str1 is Eventually I stopped caring... nobody noticed.