【问题标题】:VS Code: namespace "std" has no member "format" message but it compilesVS 代码:命名空间 \"std\" 没有成员 \"format\" 消息但它编译
【发布时间】:2023-01-03 23:27:03
【问题描述】:

我在 Visual Studio 2022 中编写了一些代码,然后将其复制到 VS Code,以便将其编译为节点模块。我在 Visual Studio 中没有收到任何错误,但在 VS Code 中收到以下错误:

namespace "std" has no member "format" C/C++(135)。

代码编译没有错误并且工作正常,但我的工作区被错误消息污染了。

如果有人能指出这些消息的原因以及如何抑制它们,我将不胜感激。

下面是详细的编译信息:

> node-gyp rebuild -j max && set_modules && tsc && node ./final/index.js

gyp info it worked if it ends with ok
gyp info using node-gyp@9.0.0
gyp info using node@16.14.0 | win32 | x64
gyp info find Python using Python version 3.10.2 found at "C:\Python310\python.exe"
gyp info find VS using VS2022 (17.2.32519.379) found at:
gyp info find VS "C:\Program Files\Microsoft Visual Studio\2022\Community"

【问题讨论】:

  • 这看起来像一个错误,而不是警告。你确定它真的编译了吗?如果你从你的文件夹中删除可执行文件,它会在你编译后再次生成吗?
  • gcc 还没有实现 std::format。您可以使用第三方库来做很多相同的事情fmt。
  • @Yksisarvinen:是的,它确实编译。我现在正在处理它,做出反映在模块中的更改等。
  • 大多数 IDE 使用不同的“编译器”来进行语法高亮显示,就像它们用于实际编译一样。差异几乎可以肯定归结于此。 std::format 是 C++20 及更高版本。
  • 看起来您收到的是智能感知错误,而不是编译器错误。您希望能够区分两者,并在提问时告诉我们您得到了什么。

标签: c++ visual-studio-code


【解决方案1】:

VS Code 创建一个 .vscode 文件夹,其中包含一个文件 c_cpp_properties.json。

将 "cppStandard": "c++17", 行更改为 "cppStandard": "c++20", 可启用 C++20 的 IntelliSense。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题。我为这个问题添加了 "C_Cpp.default.cppStandard": "c++20" 到 .vscode/setting.json 并解决了它。

    【讨论】:

      猜你喜欢
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 2017-02-13
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-20
      相关资源
      最近更新 更多