i need to execute an for loop till the queue is empty my code
queue<string> q;
for(int i=0;i<q.size(),i++)
{
// some operation goes here
// some datas are added to queue
}
while (!q.empty())
{
std::string str = q.front();
// TODO: do something with str.
q.pop();
}
It's the same code as the best answer, but using for
loop. It looks cleaner for me.
for (; !q.empty(); q.pop())
{
auto& str = q.front();
// TODO: do something with str.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With