queue_constructor.html

来自「从www.CppReference.com打包的C++参考手册」· HTML 代码 · 共 83 行

HTML
83
字号
<!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>Queue constructor</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++ Queues</a> &gt; <a href=    "queue_constructor.html">Queue constructor</a>  </div>  <div class="name-format">    Queue constructor  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;queue&gt;  queue();  queue( const Container&amp; con );</pre>  <p>Queues have a default constructor as well as a copy constructor  that will create a new queue out of the container <em>con</em>.  </p>  <p>For example, the following code creates a queue of strings,  populates it with input from the user, and then displays it back to  the user:</p>  <pre class="example-code">  queue&lt;string&gt; waiting_line;  while( waiting_line.size() &lt; 5 ) {    cout &lt;&lt; "Welcome to the line, please enter your name: ";    string s;    getline( cin, s );    waiting_line.push(s);  }  while( !waiting_line.empty() ) {    cout &lt;&lt; "Now serving: " &lt;&lt; waiting_line.front() &lt;&lt; endl;    waiting_line.pop();  }</pre>  <p>When run, the above code might produce this output:</p>  <pre class="example-code">  Welcome to the line, please enter your name: Nate  Welcome to the line, please enter your name: lizzy   Welcome to the line, please enter your name: Robert B. Parker  Welcome to the line, please enter your name: ralph  Welcome to the line, please enter your name: Matthew  Now serving: Nate  Now serving: lizzy  Now serving: Robert B. Parker  Now serving: ralph  Now serving: Matthew</pre>  </div>  </td>    </tr>  </table></body></html>

⌨️ 快捷键说明

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