gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:17:35 25 4
gpt4 key购买 nike

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

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();
}

关于c++ - 如何在C++中执行for循环直到队列为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3879055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com