📄 append.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <meta name="generator" content= "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"> <title>append</title> <link href="../cppreference.css" rel="stylesheet" type="text/css"></head><body><table> <tr> <td> <div class="body-content"> <div class="header-box"> <a href="../index.html">cppreference.com</a> > <a href= "index.html">C++ Strings</a> > <a href="append.html">append</a> </div> <div class="name-format"> append </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <string> string& append( const string& str ); string& append( const char* str ); string& append( const string& str, <strong>size_type</strong> index, <strong>size_type</strong> len ); string& append( const char* str, <strong>size_type</strong> num ); string& append( <strong>size_type</strong> num, char ch ); string& append( <a href="../iterators.html">input_iterator</a> start, <a href="../iterators.html">input_iterator</a> end );</pre> <p>The append() function either:</p> <ul> <li>appends <em>str</em> on to the end of the current string,</li> <li>appends a substring of <em>str</em> starting at <em>index</em> that is <em>len</em> characters long on to the end of the current string,</li> <li>appends <em>num</em> characters of <em>str</em> on to the end of the current string,</li> <li>appends <em>num</em> repititions of <em>ch</em> on to the end of the current string,</li> <li>or appends the sequence denoted by <em>start</em> and <em>end</em> on to the end of the current string.</li> </ul> <p>For example, the following code uses append() to add 10 copies of the '!' character to a string:</p> <pre class="example-code"> string str = "Hello World"; str.append( 10, '!' ); cout << str << endl; </pre> <p>That code displays:</p> <pre class="example-code"> Hello World!!!!!!!!!! </pre> <p>In the next example, append() is used to concatenate a substring of one string onto another string:</p> <pre class="example-code"> 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; </pre> <p>When run, the above code displays:</p> <pre class="example-code"> str1 is Eventually I stopped caring...nobody noticed. </pre> </div> </td> </tr> </table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -