How to initialize and print queue with strings in C++

1 Answer

0 votes
#include <iostream>
#include <string>
#include <queue>

using std::cout;
using std::endl;
using std::string;
using std::queue;

void print(queue<string> q)
{
	while (!q.empty()) {
		cout << q.front() << " ";
		q.pop();
	}
	cout << endl;
}

int main()
{
	queue<string> q;

	q.push("c++");
	q.push("java");
	q.push("php");

	print(q);
	
	return 0;
}

/*
run:

c++ java php

*/

 



answered May 11, 2018 by avibootz

Related questions

1 answer 169 views
1 answer 156 views
156 views asked Apr 5, 2020 by avibootz
1 answer 191 views
1 answer 214 views
2 answers 176 views
...