📄 assign1.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>assign</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="assign1.html">assign</a> </div> <div class="name-format"> assign </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <string> void assign( <strong>size_type</strong> num, const char& val ); void assign( <a href="../iterators.html">input_iterator</a> start, <a href="../iterators.html">input_iterator</a> end ); string& assign( const string& str ); string& assign( const char* str ); string& assign( const char* str, <strong>size_type</strong> num ); string& assign( const string& str, <strong>size_type</strong> index, <strong>size_type</strong> len ); string& assign( <strong>size_type</strong> num, const char& ch );</pre> <p>The deafult assign() function gives the current string the values from <em>start</em> to <em>end</em>, or gives it <em>num</em> copies of <em>val</em>.</p> <p>In addition to the normal (C++ Lists) <a href= "../cpplist/assign.html">assign</a>() functionality that all C++ containers have, strings possess an assign() function that also allows them to:</p> <ul> <li>assign <em>str</em> to the current string,</li> <li>assign the first <em>num</em> characters of <em>str</em> to the current string,</li> <li>assign a substring of <em>str</em> starting at <em>index</em> that is <em>len</em> characters long to the current string,</li> </ul> <p>For example, the following code:</p> <pre class="example-code"> string str1, str2 = "War and Peace"; str1.assign( str2, 4, 3 ); cout << str1 << endl; </pre> <p>displays</p> <pre class="example-code"> and </pre> <p>This function will destroy the previous contents of the string.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> (C++ Lists) <a href="../cpplist/assign.html">assign</a> </div> </div> </td> </tr> </table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -