
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
queue::emplace() in C++ STL
In this article we will be discussing the working, syntax and examples of queue::emplace() function in C++ STL.
What is a queue in C++ STL?
Queue is a simple sequence or data structure defined in the C++ STL which does insertion and deletion of the data in FIFO(First In First Out) fashion. The data in a queue is stored in continuous manner. The elements are inserted at the end and removed from the starting of the queue. In C++ STL there is already a predefined template of queue, which inserts and removes the data in the similar fashion of a queue.
What is queue::emplace()?
queue::emplace() is an inbuilt function in C++ STL which is declared in
Syntax
myqueue.emplace(value_type &t);
This function accepts one parameter, i.e. the element which is to be inserted in the associated queue container.
Return value
This function returns nothing.
Example
Input: queue<int> myqueue = {10, 20, 30, 40}; myqueue.emplace(50); Output: Elements In the queue = 10 20 30 40 50
Example
#include <iostream> #include <queue> using namespace std; int main (){ queue<int> Queue; Queue.emplace(10); Queue.emplace(20); Queue.emplace(30); Queue.emplace(40); Queue.emplace(50); cout<<"Elements in Queue are: "; while(!Queue.empty()){ cout << ' ' << Queue.front(); Queue.pop(); } return 0; }
Output
If we run the above code it will generate the following output −
Elements in Queue are: 10 20 30 40 50
Example
#include <iostream> #include <queue> using namespace std; int main(){ queue<string> Queue; Queue.emplace("Welcome"); Queue.emplace("To"); Queue.emplace("Tutorials"); Queue.emplace("Point"); cout<<"String is : "; while (!Queue.empty()){ cout << ' ' << Queue.front(); Queue.pop(); } return 0; }
Output
If we run the above code it will generate the following output −
String is : Welcome To Tutorials Point
- Related Articles
- map emplace() in C++ STL
- multimap::emplace() in C++ STL
- stack emplace() in C++ STL
- emplace vs insert in C++ STL
- list emplace() function in C++ STL
- queue::front() and queue::back() in C++ STL
- queue::empty() and queue::size() in C++ STL
- queue::push() and queue::pop() in C++ STL
- queue::swap() in C++ STL
- C++ Program to Implement Queue in STL
- Priority Queue in C++ Standard Template Library (STL)
- STL Priority Queue for Structure or Class in C++
- Queue Interface In C#
- Orderly Queue in C++
- Stack and Queue in C#
