📄 rfind.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>rfind</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="rfind.html">rfind</a> </div> <div class="name-format"> rfind </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <string> <strong>size_type</strong> rfind( const string& str, <strong>size_type</strong> index ); <strong>size_type</strong> rfind( const char* str, <strong>size_type</strong> index ); <strong>size_type</strong> rfind( const char* str, <strong>size_type</strong> index, <strong>size_type</strong> num ); <strong>size_type</strong> rfind( char ch, <strong>size_type</strong> index );</pre> <p>The rfind() function either:</p> <ul> <li>returns the location of the first occurrence of <em>str</em> in the current string, doing a reverse search from <em>index</em>, string::npos if nothing is found,</li> <li>returns the location of the first occurrence of <em>str</em> in the current string, doing a reverse search from <em>index</em>, searching at most <em>num</em> characters, string::npos if nothing is found,</li> <li>or returns the location of the first occurrence of <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, in the following code, the first call to rfind() returns string::npos, because the target word is not within the first 8 characters of the string. However, the second call returns 9, because the target word is within 20 characters of the beginning of the string.</p> <pre class="example-code"> int loc; string s = "My cat's breath smells like cat food."; loc = s.rfind( "breath", 8 ); cout << "The word breath is at index " << loc << endl; loc = s.rfind( "breath", 20 ); cout << "The word breath is at index " << loc << endl; </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_not_of.html">find_last_not_of</a><br> <a href="find_last_of.html">find_last_of</a> </div> </div> </td> </tr> </table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -