具有多变量初始化的C ++ for-loop结构 [英] C++ for-loop structure with multiple variable initialization
本文介绍了具有多变量初始化的C ++ for-loop结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在第二个for循环,我从gcc得到以下错误:
On the 2nd for-loop, I get the following error from gcc:
error: expected unqualified-id before 'int'
我不知道我缺少什么。我查看了一个for循环应该如何看起来的文档,我仍然困惑。这里有什么问题?
I'm not sure what I'm missing. I've looked over documentation for how a for-loop should look and I'm still confused. What's wrong here?
#include <iostream>
#include <vector>
int main() {
std::vector<int> values;
for (int i = 0; i < 20; i++) {
values.push_back(i);
}
std::cout << "Reading values from 'std::vector values'" << std::endl;
for (int i = 0, int col = 0; i < values.size(); i++, col++) {
if (col > 10) { std::cout << std::endl; col == 0; }
std::endl << values[i] << ' ';
}
}
推荐答案
在之前
Try without the int
before col
.
for(int i = 0,col = 0; i
这篇关于具有多变量初始化的C ++ for-loop结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文