Using #include <queue>

Published on: October 16, 2011

In my last tutorial, I introduced queues the long way. In this tutorial, I show you how to use #include <queue> properly in C++. I cover many of the basic functions included with queue including push, pop, empty, size, front, and back.

This is a simple tutorial and can be mastered within minutes. It shortens the last tutorial greatly and gives you an insight on how to properly use #include in C++.

If you have any questions about the program or anything in general relating to beginner C++ Programming, feel free to ask.

Remember to checkout the Codesnip below to review the C++ code yourself! Feel free to copy the code, but I ask that you please provide credit if you leave the code unchanged when you use it.


//Name:  Nazmus
//Program: Using #include<queue> in C++

#include <iostream>
#include <string>
#include <queue>

using namespace std;

int main()

 queue<string> students;
 string stuname;
 char quest;

 cout << "Do you want to enter data (Y/N)? ";
 cin >> quest; 

 while (quest =='Y' || quest == 'y')

  cout << "Please enter data for queue: ";
  cin >> stuname;


  cout << "Do you want to enter data (Y/N)? ";
  cin >> quest; 

 cout << endl;

 cout << students.back() << endl << endl;
 cout << students.size() << endl << endl;

 while (!students.empty())
  cout << students.front() << endl;