Deque Emplace Back Function

C++ emplace_back

C++ Deque emplace_back function adds a new element at the end of the deque and the size of the container is increased by one.

Syntax

Example

void emplace_back(value_type val);

Parameter

val : New value to be inserted at the end of the deque.

Return value

It does not return any value.

Example 1

Let's see a simple example

Example

#include <iostream>
#include<deque>
using namespace std;
int main()
{
  deque<int> d={1,2,3,4};
  deque<int>::iterator itr;
  d.emplace_back(5);
  for(itr=d.begin();itr!=d.end();++itr)
  std::cout << *itr <<" ";
  return 0;
}

Output:

Output

1 2 3 4 5

In this example, emplace_back function adds a new element i.e 5 at the end of the deque.

Example 2

Let's see a simple example

Example

#include <iostream>
#include<deque>
using namespace std;
int main()
{
  deque<char> ch={'j','a','v'};
  deque<char>::iterator itr;
  ch.emplace_back('a');
  for(itr=ch.begin();itr!=ch.end();++itr)
  std::cout << *itr;
    return 0;
}

Output:

In this example, emplace_back function adds a new element i.e 'a' at the end of the deque.

Input Required

This code uses input(). Please provide values below: