📄 copy.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>copy</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="copy.html">copy</a> </div> <div class="name-format"> copy </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <string> <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'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, '\0', 30 ); string str = "Trying is the first step towards failure."; str.copy( buf, 24 ); cout << buf << 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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -