rjc*_*810 2 c++ macos computer-science include-path visual-studio-code
我是 C++ 和 vscode 的新手,所以我不确定如何解决这个问题。我试图通过https://code.visualstudio.com/docs/cpp/config-clang-mac 上的教程,但如果没有 iostream、vector 和字符串错误。我还在这里看到了一些帖子,指出我应该在配置中更改 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;
}
Run Code Online (Sandbox Code Playgroud)
在前三行中,我收到了错误"cannot open source file {the included import's name}"
。编译器指出#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/Users/rjc/projects/helloworld/helloworld.cpp).C/C++(1696)
我在我的 includePath 中添加了这一行(配置页面声明每行添加一个 includePath,因此我将这两个语句放在单独的行中):
${workspaceFolder}/**
/Users/rjc/projects/helloworld/
然而,这并没有减少错误的数量。我不确定在这里做什么,因为教程似乎对我不起作用。
我正在运行 macOS Big Sur (11.1) 和 clang 版本 12.0.0。对于我为什么会遇到这些问题的任何直觉,我将不胜感激。
您的 includePath 只有 ${workspaceFolder}。您需要将路径添加到您的系统目录。运行此命令并确保打印出的所有路径都列在您的 c_cpp_properties.json 中:gcc -v -E -x c++ -
小智 5
如上所述,你应该
gcc -v -E -x c++ -
cntrl + p
在 vscode 中点击) 归档时间: |
|
查看次数: |
9063 次 |
最近记录: |