gpt4 book ai didi

c++ - vscode 无法打开源文件 "iostream"

转载 作者:行者123 更新时间:2023-12-04 16:25:27 32 4
gpt4 key购买 nike

我是 C++ 和 vscode 的新手,所以我不确定如何解决这个问题。我试过在 https://code.visualstudio.com/docs/cpp/config-clang-mac 上完成教程但我似乎无法在没有 iostream、vector 和 string 错误的情况下粘贴他们的“hello world”代码。我还在这里看到了一些帖子,表明我应该在配置中更改 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 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++ -

关于c++ - vscode 无法打开源文件 "iostream",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65421161/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com