cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : deque : push_back
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
deque
comparison operators
deque::deque
deque::~deque
member functions:
· deque::assign
· deque::at
· deque::back
· deque::begin
· deque::clear
· deque::empty
· deque::end
· deque::erase
· deque::front
· deque::get_allocator
· deque::insert
· deque::max_size
· deque::operator=
· deque::operator[]
· deque::pop_back
· deque::pop_front
· deque::push_back
· deque::push_front
· deque::rbegin
· deque::rend
· deque::resize
· deque::size
· deque::swap

-

deque::push_back public member function
void push_back ( const T& x );

Add element at the end

Adds a new element at the end of the deque container, after its current last element. The content of this new element is initialized to a copy of x.

This effectively increases the container size by one and invalidates all iterators to the deque, but has no effect on the validity of references to elements of the deque.

Parameters

x
Value to be copied to the new element.
T is the first template parameter (the type of the elements stored in the deque container).

Return value

none

Example

// deque::push_back
#include <iostream>
#include <deque>
using namespace std;

int main ()
{
  deque<int> mydeque;
  int myint;

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

  do {
    cin >> myint;
    mydeque.push_back (myint);
  } while (myint);

  cout << "mydeque stores " << (int) mydeque.size() << " numbers.\n";

  return 0;
}
The example uses push_back to add a new element to the container each time a new integer is read.

Complexity

Constant.

See also

deque::push_front Insert element at beginning (public member function)
deque::pop_back Delete last element (public member function)
deque::insert Insert elements (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us