⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 all.html

📁 从www.CppReference.com打包的C++参考手册
💻 HTML
📖 第 1 页 / 共 4 页
字号:
      <th class="code-table-th">3-eyed fish</th>      <th class="code-table-th">inanimate carbon rod</th>    </tr>    <tr>      <td class="code-table-td">&quot;Homer&quot;.compare( x )</td>      <td class="code-table-td">0</td>      <td class="code-table-td">-1</td>      <td class="code-table-td">1</td>      <td class="code-table-td">-1</td>    </tr>    <tr>      <td class="code-table-td">&quot;Marge&quot;.compare( x )</td>      <td class="code-table-td">1</td>      <td class="code-table-td">0</td>      <td class="code-table-td">1</td>      <td class="code-table-td">-1</td>    </tr>    <tr>      <td class="code-table-td">&quot;3-eyed fish&quot;.compare( x      )</td>      <td class="code-table-td">-1</td>      <td class="code-table-td">-1</td>      <td class="code-table-td">0</td>      <td class="code-table-td">-1</td>    </tr>    <tr>      <td class="code-table-td">&quot;inanimate carbon      rod&quot;.compare( x )</td>      <td class="code-table-td">1</td>      <td class="code-table-td">1</td>      <td class="code-table-td">1</td>      <td class="code-table-td">0</td>    </tr>  </table>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="string_operators.html">String operators</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    copy  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;string&gt;  <strong>size_type</strong> copy( char* str, <strong>size_type</strong> num, <strong>size_type</strong> index = 0 );</pre>  <p>The copy() function copies <em>num</em> characters of the current  string (starting at <em>index</em> if it&#39;s specified, 0  otherwise) into <em>str</em>.</p>  <p>The return value of copy() is the number of characters copied.</p>  <p>For example, the following code uses copy() to extract a substring  of a string into an array of characters:</p>  <pre class="example-code"> char buf[30]; memset( buf, &#39;\0&#39;, 30 ); string str = &quot;Trying is the first step towards failure.&quot;; str.copy( buf, 24 ); cout &lt;&lt; buf &lt;&lt; endl;               </pre>  <p>When run, this code displays:</p>  <pre class="example-code"> Trying is the first step               </pre>  <p>Note that before calling copy(), we first call (Standard C String  and Character) <a href="../stdstring/memset.html">memset</a>() to  fill the destination array with copies of the <strong>NULL</strong>  character. This step is included to make sure that the resulting  array of characters is <strong>NULL</strong>-terminated.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="substr.html">substr</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    data  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;string&gt;  const char *data();</pre>  <p>The function data() returns a pointer to the first character in  the current string.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="string_operators.html">String operators</a><br>    <a href="c_str.html">c_str</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    empty  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;string&gt;  bool empty() const;</pre>  <p>The empty() function returns true if the string has no elements,  false otherwise.</p>  <p>For example:</p>  <pre class="example-code">  string s1;  string s2("");  string s3("This is a string");  cout.setf(ios::boolalpha);  cout &lt;&lt; s1.empty() &lt;&lt; endl;  cout &lt;&lt; s2.empty() &lt;&lt; endl;  cout &lt;&lt; s3.empty() &lt;&lt; endl;</pre>  <p>When run, this code produces the following output:</p>  <pre class="example-output">  true  true  false</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">    end  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;string&gt;  iterator end();  const_iterator end() const;</pre>  <p>The end() function returns an iterator just past the end of the  string.</p>  <p>Note that before you can access the last element of the string  using an iterator that you get from a call to end(), you&#39;ll have  to decrement the iterator first.</p>  <p>For example, the following code uses <a href=  "begin.html">begin</a>() and end() to iterate through all of the  members of a vector:</p>  <pre class="example-code"> vector&lt;int&gt; v1( 5, 789 ); vector&lt;int&gt;::iterator it; for( it = v1.begin(); it != v1.end(); it++ ) {   cout &lt;&lt; *it &lt;&lt; endl; }              </pre>  <p>The iterator is initialized with a call to <a href=  "begin.html">begin</a>(). After the body of the loop has been  executed, the iterator is incremented and tested to see if it is  equal to the result of calling end(). Since end() returns an iterator  pointing to an element just after the last element of the vector, the  loop will only stop once all of the elements of the vector have been  displayed.</p>  <p>end() 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="rbegin.html">rbegin</a><br>    <a href="rend.html">rend</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    erase  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;string&gt;  iterator erase( iterator loc );  iterator erase( iterator start, iterator end );  string&amp; erase( <strong>size_type</strong> index = 0, <strong>size_type</strong> num = npos );</pre>  <p>The erase() function either:</p>  <ul>    <li>removes the character pointed to by <em>loc</em>, returning an    iterator to the next character,</li>    <li>removes the characters between <em>start</em> and <em>end</em>    (including the one at <em>start</em> but not the one at    <em>end</em>), returning an iterator to the character after the    last character removed,</li>    <li>or removes <em>num</em> characters from the current string,    starting at <em>index</em>, and returns *this.</li>  </ul>  <p>The parameters <em>index</em> and <em>num</em> have default  values, which means that erase() can be called with just  <em>index</em> to erase all characters after <em>index</em> or with  no arguments to erase all characters.</p>  <p>For example:</p>  <pre class="example-code">   string s(&quot;So, you like donuts, eh? Well, have all the donuts in the world!&quot;);   cout &lt;&lt; &quot;The original string is &#39;&quot; &lt;&lt; s &lt;&lt; &quot;&#39;&quot; &lt;&lt; endl;             s.erase( 50, 14 );   cout &lt;&lt; &quot;Now the string is &#39;&quot; &lt;&lt; s &lt;&lt; &quot;&#39;&quot; &lt;&lt; endl;   s.erase( 24 );   cout &lt;&lt; &quot;Now the string is &#39;&quot; &lt;&lt; s &lt;&lt; &quot;&#39;&quot; &lt;&lt; endl;   s.erase();   cout &lt;&lt; &quot;Now the string is &#39;&quot; &lt;&lt; s &lt;&lt; &quot;&#39;&quot; &lt;&lt; endl;               </pre>  <p>will display</p>  <pre class="example-code">   The original string is &#39;So, you like donuts, eh? Well, have all the donuts in the world!&#39;   Now the string is &#39;So, you like donuts, eh? Well, have all the donuts&#39;   Now the string is &#39;So, you like donuts, eh?&#39;   Now the string is &#39;&#39;         </pre>  <p>erase() runs in <a href="../complexity.html">linear time</a>.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="insert.html">insert</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    find  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;string&gt;  <strong>size_type</strong> find( const string&amp; str, <strong>size_type</strong> index );  <strong>size_type</strong> find( const char* str, <strong>size_type</strong> index );  <strong>size_type</strong> find( const char* str, <strong>size_type</strong> index, <strong>size_type</strong> length );  <strong>size_type</strong> find( char ch, <strong>size_type</strong> index );</pre>  <p>The function find() either:</p>  <ul>    <li>returns the first occurrence of <em>str</em> within the current    string, starting at <em>index</em>, string::npos if nothing is    found,</li>    <li>if the <em>length</em> parameter is given, then find() returns    the first occurrence of the first <em>length</em> characters of    <em>str</em> within the current string, starting at    <em>index</em>, string::npos if nothing is found,</li>    <li>or returns the index of the first occurrence <em>ch</em> within    the current string, starting at <em>index</em>, string::npos if    nothing is found.</li>  </ul>  <p>For example:</p>  <pre class="example-code">   string str1( &quot;Alpha Beta Gamma Delta&quot; );   string::size_type loc = str1.find( &quot;Omega&quot;, 0 );   if( loc != string::npos ) {     cout &lt;&lt; &quot;Found Omega at &quot; &lt;&lt; loc &lt;&lt; endl;   } else {     cout &lt;&lt; &quot;Didn&#39;t find Omega&quot; &lt;&lt; endl;            }</pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <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><br>    <a href="rfind.html">rfind</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    find_first_not_of  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;string&gt;  <strong>size_type</strong> find_first_not_of( const string&amp; str, <strong>size_type</strong> index = 0 );  <strong>size_type</strong> find_first_not_of( const char* str, <strong>size_type</strong> index = 0 );  <strong>size_type</strong> find_first_not_of( const char* str, <strong>size_type</strong> index, <strong>size_type</strong> num );  <strong>size_type</strong> find_first_not_of( char ch, <strong>size_type</strong> index = 0 );</pre>  <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 <em>str</em>, beginning    the search at <em>index</em>, string::npos if nothing is    found,</li>    <li>searches 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 first occurrence of a character    that does not match <em>ch</em> in the current string, starting the    search at <em>index</em>, string::npos if nothing is found.</li>  </ul>  <p>For example, the following code searches a string of text for the  first character that is not a lower-case character, space, comma, or  hypen:</p>  <pre class="example-code">  string lower_case = &quot;abcdefghijklmnopqrstuvwxyz ,-&quot;;  string str = &quot;this is the lower-case part, AND THIS IS THE UPPER-CASE PART&quot;;  cout &lt;&lt; &quot;first non-lower-case letter in str at: &quot; &lt;&lt; str.find_first_not_of(lower_case) &lt;&lt; endl;            </pre>  <p>When run, find_first_not_of() finds the first upper-case letter in  <em>str</em> at index 29 and displays this output:</p>  <pre class="example-code">  first non-lower-case letter in str at: 29              </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><br>    <a href="rfind.html">rfind</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    find_first_of  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;string&gt;  <strong>size_type</strong> find_first_of( const string &amp;str, <strong>size_type</strong> index = 0 );  <strong>size_type</strong> find_first_of( const char* str, <strong>size_type</strong> index = 0 );  <strong>size_type</strong> find_first_of( const char* str, <strong>size_type</strong> index, <strong>size_type</strong> num );  <strong>size_type</strong> find_first_of( char ch, <strong>size_type</strong> index = 0 );</pre>  <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 <em>str</em>, beginning the    search at <em>index</em>, string::npos if nothing is found,</li>    <li>searches 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 returns the index of the first occurrence of <em>ch</em> in    the current string, starting the search at <em>index</em>,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -