public member function
<queue>

std::queue::push

void push (const value_type& val);
void push (const value_type& val);void push (value_type&& val);
Insert element
Inserts a new element at the end of the queue, after its current last element. The content of this new element is initialized to val.

This member function effectively calls the member function push_back of the underlying container object.

Parameters

val
Value to which the inserted element is initialized.
Member type value_type is the type of the elements in the container (defined as an alias of the first class template parameter, T).

Return value

none

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// queue::push/pop
#include <iostream>       // std::cin, std::cout
#include <queue>          // std::queue

int main ()
{
  std::queue<int> myqueue;
  int myint;

  std::cout << "Please enter some integers (enter 0 to end):\n";

  do {
    std::cin >> myint;
    myqueue.push (myint);
  } while (myint);

  std::cout << "myqueue contains: ";
  while (!myqueue.empty())
  {
    std::cout << ' ' << myqueue.front();
    myqueue.pop();
  }
  std::cout << '\n';

  return 0;
}
The example uses push to add a new elements to the queue, which are then popped out in the same order.

Complexity

One call to push_back on the underlying container.

Data races

The container and up to all its contained elements are modified.

Exception safety

Provides the same level of guarantees as the operation performed on the underlying container object.

See also