我还在这里看到过一些帖子,指示我应该更改配置中的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}"
。编译器显示如下:
我在我的includePath中添加了这一行,如下所示(配置页面说明每行添加一个includePath,因此我将这两个语句放在不同的行上):检测到#include错误,请更新您的includePath。此翻译单元(/Users/rjc/projects/helloworld/helloworld.cpp)已禁用波浪线。C/C++(1696)
${workspaceFolder}/**
/Users/rjc/projects/helloworld/
然而,这并没有减少错误数量。我不确定该怎么做,因为教程似乎对我不起作用。我正在运行macOS 11.1(Big Sur),Clang版本为12.0.0。为什么会出现这些问题?
<iostream>
替换为"iostream"
...<header_file>
和"header_file"
之间有区别。 这里有一些你会发现有用的东西:https://dev59.com/SXVD5IYBdhLWcg3wTZ1m - Novus Edge#include <iostream>
是正确的代码。 - john