我是 C++ 和 Visual Studio Code 的新手,所以我不确定如何解决这个问题。我试图通过 在 Visual Studio Code 中使用 Clang 中 的教程,但我似乎无法粘贴他们的“ Hello, World! ”没有 iostream 、 vector 和 string 错误的代码。
我还在这里看到帖子表明我应该更改配置中的 includePath 字符串数组,但是将路径添加到我的项目文件夹似乎并不能消除这些错误。我在这里不知所措,因为到目前为止我所看到的一切仍然不起作用。
导致这些错误的代码已直接从上面的教程中复制粘贴:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
在前三行中,我收到错误 "cannot open source file {the included import's name}"
。编译器指出:
#include 检测到错误。请更新您的 includePath。此翻译单元禁用曲线 (/Users/rjc/projects/helloworld/helloworld.cpp).C/C++(1696)
我在我的 includePath 中添加了这一行(配置页面状态每行添加一个 includePath,所以我将这两个语句放在不同的行上):
${workspaceFolder}/**
/Users/rjc/projects/helloworld/
然而,这并没有减少错误的数量。我不太确定在这里做什么,因为该教程似乎对我不起作用。
我正在运行带有 Clang 版本 12.0.0 的 macOS 11.1 (Big Sur)。为什么我会有这些问题?
原文由 rjc810 发布,翻译遵循 CC BY-SA 4.0 许可协议
您的 includePath 只有
${workspaceFolder}
。您需要将路径添加到系统目录。运行此命令并确保打印出的所有路径都列在您的 _c_cppproperties.json 文件中:gcc -v -E -x c++ -