【问题标题】:C++ std_lib_facilities.h file in VSCode (Mac) 2020VSCode (Mac) 2020 中的 C++ std_lib_facilities.h 文件
【发布时间】:2020-04-11 21:07:48
【问题描述】:

我刚刚开始学习如何编程。我在我的 Mac 和 C/C++ 扩展上设置了 VSCode。我从 Stroustrup 的 Programming and Principles 书中编写了 helloworld 程序。我将 std_lib_facilities.h 文件放在与 helloworld.cpp 文件相同的文件夹中。我仍然收到错误消息:#include 检测到错误。请更新您的 includePath。此翻译单元已禁用 Squiggles。

为什么我仍然收到错误消息?这本书说我需要的只是将 std_lib_facilities.h.txt 文件与我的 .cpp 程序放在同一目录中。它们在同一个文件夹中,为什么会出现此错误?

我的代码:

#include "std_lib_facilites.h"

int main()
{
    cout << "Hello World \n";
    return 0;
}

【问题讨论】:

  • 这能回答你的问题吗? Is c++ std_lib_facilities.h still used?
  • 谢谢,我现在为获取文本文件所做的只是输入:#include "full directory path",即:#include "Users/Venkat/project/helloworld/std_lib_facilites.h"
  • 感谢 Gino,从您链接的问题中的一个答案/cmets 中得知,我必须下载新版本的 std_lib_facilities 文件,结果我必须在 .txt 之后编写 .txt。 h也是!

标签: c++ visual-studio-code


【解决方案1】:

首先,你的文件名有错别字。

#include "std_lib_facilites.h"

应该是std_lib_facilities.h (source 1, source 2)。
并确保将其保存为.h

其次,可以配置一个.vscode/c_cpp_properties.json文件来指定头文件的路径。请参阅JSON schema reference 的 VS Code 文档。

  1. 打开命令面板
  2. 选择“C/C++:编辑配置 (JSON)”
  3. 设置includePath
 "configurations": [
     {
         "name": "Mac",
         "includePath": [
             "${workspaceFolder}/**",
             "/path/to/headers"
         ],
         ...
     }
 ],

默认情况下,它已经有"${workspaceFolder}/**",它应该在您的工作区(及其子文件夹)中搜索头文件。但您也可以指定其他文件夹的路径。

【讨论】:

    猜你喜欢
    • 2021-12-19
    • 2021-12-22
    • 2018-02-03
    • 1970-01-01
    • 1970-01-01
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    相关资源
    最近更新 更多