说我有以下循环:C++如何跳过接下来的2次迭代循环的,即多继续
vector <string> args;
for (string s : args)
{
if (s == "condition")
continue; // skips to next iteration
}
我怎么能跳过多次迭代在这种情况下?有没有像多个继续声明?
说我有以下循环:C++如何跳过接下来的2次迭代循环的,即多继续
vector <string> args;
for (string s : args)
{
if (s == "condition")
continue; // skips to next iteration
}
我怎么能跳过多次迭代在这种情况下?有没有像多个继续声明?
考虑使用for
回路搭配指数:
for (size_t i = 0; i < args.size(); i++)
{
if (args[i] == "condition") {
i++;
continue;
}
}
您可以使用迭代器。
auto it_end = --args.end();
for(auto it = args.begin(); it != args.end(); it++){
if (*it == "condition" && it != it_end) it++;
}
比迭代器更好的方法 – jamek