【问题标题】:Can't initialize variables in for loop in C in VSCODE无法在VSCODE中的C中初始化for循环中的变量
【发布时间】:2021-12-28 12:04:50
【问题描述】:

我认为我的 VSCode 有问题,因为我无法在 C 的循环中初始化变量 例如:

    #include <stdio.h>

    int main(){
     for(int i = 0; i < 5; i++){
      printf("%i", i);
     }
     }

编译错误 我该如何解决? 提前致谢

【问题讨论】:

  • 显示完整的错误信息。
  • coding.c:在函数'main'中:coding.c:4:5:错误:'for'循环初始声明只允许在C99模式coding.c:4:5:注意:使用选项 -std=c99 或 -std=gnu99 编译您的代码
  • 是什么阻止您使用指定的选项?

标签: c visual-studio-code compiler-errors vscode-settings


【解决方案1】:

在 for 循环之前声明 i 或使用“-std=c99”编译

#include <stdio.h>

int main(){
    int i = 0;
    for(i = 0; i < 5; i++){
    printf("%i", i);
    }
 }

 

【讨论】:

    猜你喜欢
    • 2012-01-02
    • 1970-01-01
    • 1970-01-01
    • 2011-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多