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

📄 fill_n.html

📁 从www.CppReference.com打包的C++参考手册
💻 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>fill_n</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> &gt; <a href=    "index.html">C++ Algorithms</a> &gt; <a href=    "fill_n.html">fill_n</a>  </div>  <div class="name-format">    fill_n  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;algorithm&gt;  #include &lt;algorithm&gt;  iterator fill_n( iterator start, size_t n, const <a href="../containers.html">TYPE</a>&amp; val );</pre>  <p>The fill_n() function is similar to (C++ I/O) <a href=  "../cppio/fill.html">fill</a>(). Instead of assigning <em>val</em> to  a range of elements, however, fill_n() assigns <em>val</em> to the  first <em>n</em> elements starting at <em>start</em>.</p>  <p>For example, the following code uses fill_n() to assign -1 to the  first half of a vector of integers:</p>  <pre class="example-code"> vector&lt;int&gt; v1; for( int i = 0; i &lt; 10; i++ ) {   v1.push_back( i ); }               cout &lt;&lt; &quot;Before, v1 is: &quot;; for( unsigned int i = 0; i &lt; v1.size(); i++ ) {   cout &lt;&lt; v1[i] &lt;&lt; &quot; &quot;; } cout &lt;&lt; endl;             fill_n( v1.begin(), v1.size()/2, -1 );          cout &lt;&lt; &quot;After, v1 is: &quot;; for( unsigned int i = 0; i &lt; v1.size(); i++ ) {   cout &lt;&lt; v1[i] &lt;&lt; &quot; &quot;; } cout &lt;&lt; endl;            </pre>  <p>When run, this code displays:</p>  <pre class="example-code"> Before, v1 is: 0 1 2 3 4 5 6 7 8 9 After, v1 is: -1 -1 -1 -1 -1 5 6 7 8 9         </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="fill.html">fill</a>  </div>  </div>  </td>    </tr>  </table></body></html>

⌨️ 快捷键说明

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