for 循环中的变量声明 - Intellisense 坚持使用 C89 标准?
Variable declaration in for loop - Intellisense stuck with C89 standard?
我有一个 C 项目,我使用“打开文件夹”选项在 VisualStudio 2019 中打开它。我添加了一个 CppProperties.json 来获取 Intellisense 运行,但现在如果我尝试在 for 循环中声明一个变量,它会抛出错误,如下所示:
for (int i = 0; i < 10; i++)
{
}
error: E0029 expected an expression
error: E0020 identifier "i" is undefined
我已经搜索了 Whosebug,发现 this thread 有人提到 C99 标准中添加了 for 循环中的变量声明。
在 VisualStudio 文档中,它说您应该将“-std=C99”添加到您的项目设置中,但我没有项目文件(因为我使用“打开文件夹”选项打开它),因此没有项目设置。
有没有办法告诉 Intellisense 使用什么 C 标准?
提前致谢。
找到了:只需添加
"compilerSwitches": "-std=c99",
给你的 CppProperties.json.
我有一个 C 项目,我使用“打开文件夹”选项在 VisualStudio 2019 中打开它。我添加了一个 CppProperties.json 来获取 Intellisense 运行,但现在如果我尝试在 for 循环中声明一个变量,它会抛出错误,如下所示:
for (int i = 0; i < 10; i++)
{
}
error: E0029 expected an expression
error: E0020 identifier "i" is undefined
我已经搜索了 Whosebug,发现 this thread 有人提到 C99 标准中添加了 for 循环中的变量声明。
在 VisualStudio 文档中,它说您应该将“-std=C99”添加到您的项目设置中,但我没有项目文件(因为我使用“打开文件夹”选项打开它),因此没有项目设置。
有没有办法告诉 Intellisense 使用什么 C 标准?
提前致谢。
找到了:只需添加
"compilerSwitches": "-std=c99",
给你的 CppProperties.json.