2
我想在逗號循環中使用逗號分隔多個初始化,但我得到下面的錯誤。在C++ for循環中的逗號運算符
在for循環的第一部分使用逗號是否合法?
error: too few template-parameter-lists
error: sEnd was not declared in this scope
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
using namespace std;
typedef vector<int> Vc;
Vc v;
for(Vc::iterator sIt = v.begin(), Vc::iterator sEnd = v.end();
sIt != sEnd; ++sIt) {
// do something
}
return 0;
}
請注意,不是正在使用的逗號運算符。 – chris
請注意,您不能以這種方式使用逗號運算符,因爲它期望其左側和右側是*表達式*。聲明不是表達式。逗號不一定表示逗號運算符。 – dyp