📄 cppstring_details.html
字号:
<li>or compare a substring of <i>str</i> to a substring of the current string, where the substring of <i>str</i> begins at zero and is <i>length2</i> characters long, and the substring of the current string begins at <i>index</i> and is <i>length</i> characters long.</li> </ul> <br> <br> <i>Related topics:</i><br> <strong><a href="#Operators">Operators</a></strong> <hr> <h2><a name="copy">copy</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> size_type copy( char *str, size_type num, size_type index );</pre> </td> </tr> </table> <p>The copy() function copies <i>num</i> characters of the current string (starting at <i>index</i>) into <i>str</i>. The return value is the number of characters copied.</p> <hr> <h2><a name="data">data</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> const char *data();</pre> </td> </tr> </table> <p>The function data() returns a pointer to the first character in the current string.</p> <i>Related topics:</i><br> <strong><a href="#c_str">c_str()</a></strong> <hr> <h2><a name="empty">empty</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> bool empty();</pre> </td> </tr> </table> <p>The empty() function returns <strong>true</strong> if the current string is empty, and <strong>false</strong> otherwise.</p> <hr> <h2><a name="end">end</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> <a href="iterators.html">iterator</a> end();</pre> </td> </tr> </table> <p>The end() function returns an <a href="iterators.html">iterator</a> to the end of the string.</p> <i>Related topics:</i><br> <strong><a href="#begin">begin()</a></strong> <hr> <h2><a name="erase">erase</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> <a href="iterators.html">iterator</a> erase( <a href="iterators.html">iterator</a> pos ); <a href="iterators.html">iterator</a> erase( <a href="iterators.html">iterator</a> start, <a href="iterators.html">iterator</a> end ); basic_string &erase( size_type index = 0, size_type num = npos );</pre> </td> </tr> </table> <p>The erase() function either:</p> <ul> <li>removes the character pointed to by <i>pos</i>, returning an <a href="iterators.html">iterator</a> to the next character,</li> <li>removes the characters between <i>start</i> and <i>end</i>, returning an <a href= "iterators.html">iterator</a> to the character after the last character removed,</li> <li>or removes <i>num</i> characters from the current string, starting at <i>index</i>, and returns <strong>*this</strong>.</li> </ul> The parameters <i>index</i> and <i>num</i> have default values, which means that erase() can be called with just <i>index</i> to erase all characters after <i>index</i> or with no arguments to erase all characters. For example: <br> <br> <pre> string s("So, you like donuts, eh? Well, have all the donuts in the world!"); cout << "The original string is '" << s << "'" << endl; s.erase( 50, 14 ); cout << "Now the string is '" << s << "'" << endl; s.erase( 24 ); cout << "Now the string is '" << s << "'" << endl; s.erase(); cout << "Now the string is '" << s << "'" << endl;</pre> <p>will display</p><pre> The original string is 'So, you like donuts, eh? Well, have all the donuts in the world!' Now the string is 'So, you like donuts, eh? Well, have all the donuts' Now the string is 'So, you like donuts, eh?' Now the string is ''</pre> <i>Related topics:</i><br> <strong><a href="#clear">clear()</a></strong> <hr> <h2><a name="find">find</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> size_type find( const basic_string &str, size_type index ); size_type find( const char *str, size_type index ); size_type find( const char *str, size_type index, size_type length ); size_type find( char ch, size_type index );</pre> </td> </tr> </table> <p>The function find() either:</p> <ul> <li>returns the first occurrence of <i>str</i> within the current string, starting at <i>index</i>, <strong>string::npos</strong> if nothing is found,</li> <li>returns the first occurrence of <i>str</i> within the current string and within <i>length</i> characters, starting at <i>index</i>, <strong>string::npos</strong> if nothing is found,</li> <li>or returns the index of the first occurrence <i>ch</i> within the current string, starting at <i>index</i>, <strong>string::npos</strong> if nothing is found.</li> </ul> For example, <br> <br> <pre> string str1( "Alpha Beta Gamma Delta" ); unsigned int loc = str1.find( "Omega", 0 ); if( loc != string::npos ) cout << "Found Omega at " << loc << endl; else cout << "Didn't find Omega" << endl; </pre> <hr> <h2><a name="find_first_of">find_first_of</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> size_type find_first_of( const basic_string &str, size_type index = 0 ); size_type find_first_of( const char *str, size_type index = 0 ); size_type find_first_of( const char *str, size_type index, size_type num ); size_type find_first_of( char ch, size_type index = 0 );</pre> </td> </tr> </table> <p>The find_first_of() function either:</p> <ul> <li>returns the index of the first character within the current string that matches any character in <i>str</i>, beginning the search at <i>index</i>, <strong>string::npos</strong> if nothing is found,</li> <li>returns the index of the first character within the current string that matches any character in <i>str</i>, beginning the search at <i>index</i> and searching at most <i>num</i> characters, <strong>string::npos</strong> if nothing is found,</li> <li>or returns the index of the first occurrence of <i>ch</i> in the current string, starting the search at <i>index</i>, <strong>string::npos</strong> if nothing is found.</li> </ul> <br> <br> <i>Related topics:</i><br> <strong><a href="#find">find()</a></strong> <hr> <h2><a name="find_first_not_of">find_first_not_of</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> size_type find_first_not_of( const basic_string &str, size_type index = 0 ); size_type find_first_not_of( const char *str, size_type index = 0 ); size_type find_first_not_of( const char *str, size_type index, size_type num ); size_type find_first_not_of( char ch, size_type index = 0 );</pre> </td> </tr> </table> <p>The find_first_not_of() function either:</p> <ul> <li>returns the index of the first character within the current string that does not match any character in <i>str</i>, beginning the search at <i>index</i>, <strong>string::npos</strong> if nothing is found,</li> <li>returns the index of the first character within the current string that does not match any character in <i>str</i>, beginning the search at <i>index</i> and searching at most <i>num</i> characters, <strong>string::npos</strong> if nothing is found,</li> <li>or returns the index of the first occurrence of a character that does not match <i>ch</i> in the current string, starting the search at <i>index</i>, <strong>string::npos</strong> if nothing is found.</li> </ul> <br> <br> <i>Related topics:</i><br> <strong><a href="#find">find()</a></strong> <hr> <h2><a name="find_last_of">find_last_of</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> size_type find_last_of( const basic_string &str, size_type index = npos ); size_type find_last_of( const char *str, size_type index = npos ); size_type find_last_of( const char *str, size_type index, size_type num ); size_type find_last_of( char ch, size_type index = npos );</pre> </td> </tr> </table> <p>The find_last_of() function either:</p> <ul> <li>returns the index of the first character within the current string that matches any character in <i>str</i>, doing a reverse search from <i>index</i>, <strong>string::npos</strong> if nothing is found,</li> <li>returns the index of the first character within the current string that matches any character in <i>str</i>, doing a reverse search from <i>index</i> and searching at most <i>num</i> characters, <strong>string::npos</strong> if nothing is found,</li> <li>or returns the index of the first occurrence of <i>ch</i> in the current string, doing a reverse search from <i>index</i>, <strong>string::npos</strong> if nothing is found.</li> </ul> <br> <br> <i>Related topics:</i><br> <strong><a href="#find">find()</a></strong> <hr> <h2><a name="find_last_not_of">find_last_not_of</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> size_type find_last_not_of( const basic_string &str, size_type index = npos ); size_type find_last_not_of( const char *str, size_type index = npos); size_type find_last_not_of( const char *str, size_type index, size_type num ); size_type find_last_not_of( char ch, size_type index = npos );</pre> </td> </tr> </table> <p>The find_last_not_of() function either:</p> <ul> <li>returns the index of the first character within the current string that does not match any character in <i>str</i>, doing a reverse search from <i>index</i>, <strong>string::npos</strong> if nothing is found,</li> <li>returns the index of the first character within the current string that does not match any character in <i>str</i>, doing a reverse search from <i>index</i> and searching at most <i>num</i> characters, <strong>string::npos</strong> if nothing is found,</li> <li>or returns the index of the first occurrence of a character that does not match <i>ch</i> in the current string, doing a reverse search from <i>index</i>, <strong>string::npos</strong> if nothing is found.</li> </ul> <br> <br> <i>Related topics:</i><br> <strong><a href="#find">find()</a></strong> <hr> <h2><a name="get_allocator">get_allocator</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> allocator_type get_allocator();</pre> </td> </tr> </table> <p>The function get_allocator() returns the allocator for the current string.</p> <hr> <h2><a name="insert">insert</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -