📄 all.html
字号:
string::npos if nothing is found.</li> </ul> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="find.html">find</a><br> <a href="find_first_not_of.html">find_first_not_of</a><br> <a href="find_last_not_of.html">find_last_not_of</a><br> <a href="find_last_of.html">find_last_of</a><br> <a href="rfind.html">rfind</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> find_last_not_of </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <string> <strong>size_type</strong> find_last_not_of( const string& str, <strong>size_type</strong> index = npos ); <strong>size_type</strong> find_last_not_of( const char* str, <strong>size_type</strong> index = npos); <strong>size_type</strong> find_last_not_of( const char* str, <strong>size_type</strong> index, <strong>size_type</strong> num ); <strong>size_type</strong> find_last_not_of( char ch, <strong>size_type</strong> index = npos );</pre> <p>The find_last_not_of() function either:</p> <ul> <li>returns the index of the last character within the current string that does not match any character in <em>str</em>, doing a reverse search from <em>index</em>, string::npos if nothing is found,</li> <li>does a reverse search in the current string, beginning at <em>index</em>, for any character that does not match the first <em>num</em> characters in <em>str</em>, returning the index in the current string of the first character found that meets this criteria, otherwise returning string::npos,</li> <li>or returns the index of the last occurrence of a character that does not match <em>ch</em> in the current string, doing a reverse search from <em>index</em>, string::npos if nothing is found.</li> </ul> <p>For example, the following code searches for the last non-lower-case character in a mixed string of characters:</p> <pre class="example-code"> string lower_case = "abcdefghijklmnopqrstuvwxyz"; string str = "abcdefgABCDEFGhijklmnop"; cout << "last non-lower-case letter in str at: " << str.find_last_not_of(lower_case) << endl; </pre> <p>This code displays the following output:</p> <pre class="example-code"> last non-lower-case letter in str at: 13 </pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="find.html">find</a><br> <a href="find_first_not_of.html">find_first_not_of</a><br> <a href="find_first_of.html">find_first_of</a><br> <a href="find_last_of.html">find_last_of</a><br> <a href="rfind.html">rfind</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> find_last_of </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <string> <strong>size_type</strong> find_last_of( const string& str, <strong>size_type</strong> index = npos ); <strong>size_type</strong> find_last_of( const char* str, <strong>size_type</strong> index = npos ); <strong>size_type</strong> find_last_of( const char* str, <strong>size_type</strong> index, <strong>size_type</strong> num ); <strong>size_type</strong> find_last_of( char ch, <strong>size_type</strong> index = npos );</pre> <p>The find_last_of() function either:</p> <ul> <li>does a reverse search from <em>index</em>, returning the index of the first character within the current string that matches any character in <em>str</em>, or string::npos if nothing is found,</li> <li>does a reverse search in the current string, beginning at <em>index</em>, for any of the first <em>num</em> characters in <em>str</em>, returning the index in the current string of the first character found, or string::npos if no characters match,</li> <li>or does a reverse search from <em>index</em>, returning the index of the first occurrence of <em>ch</em> in the current string, string::npos if nothing is found.</li> </ul> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="find.html">find</a><br> <a href="find_first_not_of.html">find_first_not_of</a><br> <a href="find_first_of.html">find_first_of</a><br> <a href="find_last_not_of.html">find_last_not_of</a><br> <a href="rfind.html">rfind</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> getline </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <string> istream& getline( istream& is, string& s, char delimiter = '\n' );</pre> <p>The C++ string class defines the global function getline() to read strings from an I/O stream. The getline() function, which is not part of the string class, reads a line from <em>is</em> and stores it into <em>s</em>. If a character <em>delimiter</em> is specified, then getline() will use <em>delimiter</em> to decide when to stop reading data.</p> <p>For example, the following code reads a line of text from <strong>stdin</strong> and displays it to <strong>stdout</strong>:</p> <pre class="example-code"> string s; getline( cin, s ); cout << "You entered " << s << endl;</pre> <p>After getting a line of data in a string, you may find that <a href="../cppsstream/index.html">string streams</a> are useful in extracting data from that string. For example, the following code reads numbers from standard input, ignoring any "commented" lines that begin with double slashes:</p> <pre class="example-code"> // expects either space-delimited numbers or lines that start with // two forward slashes (//) string s; while( getline(cin,s) ) { if( s.size() >= 2 && s[0] == '/' && s[1] == '/' ) { cout << " ignoring comment: " << s << endl; } else { istringstream ss(s); double d; while( ss >> d ) { cout << " got a number: " << d << endl; } } }</pre> <p>When run with a user supplying input, the above code might produce this output:</p> <pre class="example-code"> // test ignoring comment: // test 23.3 -1 3.14159 got a number: 23.3 got a number: -1 got a number: 3.14159 // next batch ignoring comment: // next batch 1 2 3 4 5 got a number: 1 got a number: 2 got a number: 3 got a number: 4 got a number: 5 50 got a number: 50</pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> (C++ I/O) <a href="../cppio/get.html">get</a><br> (C++ I/O) <a href="../cppio/getline.html">getline</a><br> <a href="../cppsstream/index.html">string streams</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> insert </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <string> iterator insert( iterator i, const char& ch ); string& insert( <strong>size_type</strong> index, const string& str ); string& insert( <strong>size_type</strong> index, const char* str ); string& insert( <strong>size_type</strong> index1, const string& str, <strong>size_type</strong> index2, <strong>size_type</strong> num ); string& insert( <strong>size_type</strong> index, const char* str, <strong>size_type</strong> num ); string& insert( <strong>size_type</strong> index, <strong>size_type</strong> num, char ch ); void insert( iterator i, <strong>size_type</strong> num, const char& ch ); void insert( iterator i, iterator start, iterator end );</pre> <p>The very multi-purpose insert() function either:</p> <ul> <li>inserts <em>ch</em> before the character denoted by <em>i</em>,</li> <li>inserts <em>str</em> into the current string, at location <em>index</em>,</li> <li>inserts a substring of <em>str</em> (starting at <em>index2</em> and <em>num</em> characters long) into the current string, at location <em>index1</em>,</li> <li>inserts <em>num</em> characters of <em>str</em> into the current string, at location <em>index</em>,</li> <li>inserts <em>num</em> copies of <em>ch</em> into the current string, at location <em>index</em>,</li> <li>inserts <em>num</em> copies of <em>ch</em> into the current string, before the character denoted by <em>i</em>,</li> <li>or inserts the characters denoted by <em>start</em> and <em>end</em> into the current string, before the character specified by <em>i</em>.</li> </ul> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="erase.html">erase</a><br> <a href="replace.html">replace</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> length </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <string> <strong>size_type</strong> length() const;</pre> <pre class="example-code">The length() function returns the number of elements in the current string, performing the same role as the <a href="size.html">size</a>() function. </pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="size.html">size</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> max_size </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <string> <strong>size_type</strong> max_size() const;</pre> <p>The max_size() function returns the maximum number of elements that the string can hold. The max_size() function should not be confused with the <a href="size.html">size</a>() or <a href= "capacity.html">capacity</a>() functions, which return the number of elements currently in the string and the the number of elements that the string will be able to hold before more memory will have to be allocated, respectively.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="size.html">size</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> push_back </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <string> void push_back( const <a href="../containers.html">TYPE</a>& val );</pre> <p>The push_back() function appends <em>val</em> to the end of the string.</p> <p>For example, the following code puts 10 integers into a list:</p> <pre class="example-code"> list<int> the_list; for( int i = 0; i < 10; i++ ) the_list.push_back( i ); </pre> <p>When displayed, the resulting list would look like this:</p> <pre class="example-code"> 0 1 2 3 4 5 6 7 8 9 </pre> <p>push_back() runs in <a href="../complexity.html">constant time</a>.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> (C++ Lists) <a href="../cpplist/assign.html">assign</a><br> (C++ Lists) <a href="../cpplist/insert.html">insert</a><br> (C++ Lists) <a href="../cpplist/pop_back.html">pop_back</a><br> (C++ Lists) <a href="../cpplist/push_front.html">push_front</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> rbegin </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <string> <a href="../iterators.html">reverse_iterator</a> rbegin(); const_<a href="../iterators.html">reverse_iterator</a> rbegin() const;</pre> <p>The rbegin() function returns a <a href= "../iterators.html">reverse_iterator</a> to the end of the current string.</p> <p>rbegin() runs in <a href="../complexity.html">constant time</a>.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="begin.html">begin</a><br> <a href="end.html">end</a><br> <a href="rend.html">rend</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> rend </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <string> <a href="../iterators.html">reverse_iterator</a> rend(); const_<a href="../iterators.html">reverse_iterator</a> rend() const;</pre> <p>The function rend() returns a <a href= "../iterators.html">reverse_iterator</a> to the beginning of the current string.</p> <p>rend() runs in <a href="../complexity.html">constant time</a>.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="begin.html">begin</a><br> <a href="end.html">end</a><br> <a href="rbegin.html">rbegin</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> replace </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <string> string& replace( <strong>size_type</strong> index, <strong>size_type</strong> num, const string& str );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -