相关疑难解决方法(0)

为什么c ++不支持for循环中的多个初始值设定项?

可能重复:
在C++中为什么我不能像这样编写for()循环:for(int i = 1,double i2 = 0;
为什么在C++中使用2个循环变量编写for循环是如此"难" ?

#include <iostream>
using namespace std;

int main()
{
    for (int i = 0, double j = 3.0; i < 10; i++, j+=0.1)
        cout << i << j << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

不编译,因为for循环初始化程序块中有两个声明.

但为什么?

c++ programming-languages for-loop language-lawyer

14
推荐指数
3
解决办法
2万
查看次数