📄 queue_constructor.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>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> > <a href= "index.html">C++ Queues</a> > <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 <queue> queue(); queue( const Container& 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<string> waiting_line; while( waiting_line.size() < 5 ) { cout << "Welcome to the line, please enter your name: "; string s; getline( cin, s ); waiting_line.push(s); } while( !waiting_line.empty() ) { cout << "Now serving: " << waiting_line.front() << 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -