There is no effective way to do this * . But you can do the following:
- Make a copy of the queue
- Iterate over the copy, print the front, and then send it
For instance,
#include <queue>
#include <iostream>
void print_queue(std::queue q)
{
while (!q.empty())
{
std::cout << q.front() << " ";
q.pop();
}
std::cout << std::endl;
}
int main()
{
std::queue<int> q;
for (auto i : {1,2,3,7,4,9,7,2,4}) q.push(i);
print_queue(q);
}
* , . std::queue C, , . std::queue C. , .