在使用vscode配合插件C/C++ Compile Run 写C语言程序时,报错error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode解决办法如下:
#include<stdio.h>
int main()
{
char temp[4]={70, 108, 111, 110};
for(int i=0;i<4;i++)
{
printf("%c",temp[i]);
}
return 0;
}
第一种解决办法是将for里面的循环数i初始化不要放在里面,在之前定义就可以。
#include<stdio.h>
int main()
{
int i=0;
char temp[4]={70, 108, 111, 110};
for(i=0;i<4;i++)
{
printf("%c",temp[i]);
}
return 0;
}
第二种解决办法是按照vscode的提示note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code 在编译命令中添加其中一个就可以了。
再次编译顺利通过