C++ emplace_back
The emplace_back method in C++ for deques appends a fresh element to the back of the deque, consequently enlarging the container's size by one.
Syntax
void emplace_back(value_type val);
Parameter
val : Fresh data to be added at the conclusion of the deque.
Return value
It does not return any value.
Example 1
Let's see a simple 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:
1 2 3 4 5
In this instance, the emplace_back method appends a new element, specifically the number 5, to the end of the deque.
Example 2
Let's see a simple 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 instance, the emplace_back method inserts a fresh element 'a' at the conclusion of the deque.