【问题标题】:Hello, I try to run my c code in dev-c++ and get this : [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode您好,我尝试在 dev-c++ 中运行我的 c 代码并得到以下信息:[错误] 'for' 循环初始声明仅在 C99 或 C11 模式下允许
【发布时间】:2021-06-29 06:38:06
【问题描述】:

#include

int main() { printf("你好\n");

for(int i=0; i<6; i++){
    for(int j=0; j<30; j++)
    printf("%c", (char)179);

printf("\n");
}
printf("\n"); 

printf("what\ up \n");

for(int i=0; i<6; i++){
    for(int j=0; j<30; j++)
    printf("%c", (char)179); 

printf("\n");
}
printf("\n"); 

printf("你喜欢编程吗\n");

for(int i=0; i<6; i++){
    for(int j=0; j<30; j++)
    printf("%c", (char)179); 

printf("\n");
}
printf("\n"); 

返回 0; }

【问题讨论】:

    标签: windows dev-c++


    【解决方案1】:

    如果我没记错的话,循环计数器的初始声明需要在循环之外,即:

    int i;
    for (i = 0; i < 5; i++) {
    //do stuff here
    }
    

    如您的错误消息所示,循环初始声明只能用于 C99 或 C11 标准(这是 1999 年和 2011 年发布的 C 标准)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-02
      • 2017-10-28
      • 2021-03-29
      • 2013-01-19
      • 2015-07-21
      • 2011-08-18
      • 1970-01-01
      • 2016-05-08
      相关资源
      最近更新 更多