Easy Programming

Using #include <queue> in C++:

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 <queue> in C++.

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

Click here to go back

//Name:		Nazmus
//Program:	Using #include<queue> in C++
//Website:	EasyProgramming.net


#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;

		students.push(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;

		students.pop();
	}

	cin.ignore();
	cin.get();

	//system("pause");
}