如何执行for循环直到队列在c ++中为空

raj*_*aja 6 c++ string queue loops stl

我需要执行一个for循环,直到队列为空我的代码

queue<string> q;
for(int i=0;i<q.size(),i++)
{
     // some operation goes here
     // some datas are added to queue
}
Run Code Online (Sandbox Code Playgroud)

asv*_*kau 8

while (!q.empty())
{
    std::string str = q.front();

    // TODO: do something with str.

    q.pop();
}
Run Code Online (Sandbox Code Playgroud)