fatal error: string: No such file or directory #include <string>

fatal error: string: No such file or directory #include <string>

注意,这里是 C++ 初学者,但我有使用其他语言编写代码的合理经验(以及明显不那么复杂的开发环境)。

我在 visual studio 工作,使用 visual micro 来处理一个 arduino 项目。项目的细节并不重要,因为此时,我在一个完全空的 .ino/.cpp 文件中遇到错误:

fatal error: string: No such file or directory #include <string>
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ^~~~~~~~ compilation terminated

An error was encountered during the 'Deep Search' library discovery process. Build failed for project 'CylinderPrinter'

#include <string>

// the setup function runs once when you press reset or power the board
void setup() {
    string h = "";
}

// the loop function runs over and over again until power down or reset
void loop() {
  
}

到目前为止我已经尝试了很多方法,因为这似乎是一个有点常见的错误:

  1. 大多数排列:#include "string"; #include "string.h"; #包括 ; #包括 ; #include ;使用命名空间标准(这显然是不好的做法);等等
  2. 在我的项目中包含“string”和“string.h”依赖项,而不是将它们作为外部依赖项引用(在本例中,编译器标记为 'string is undefined in this scope')
  3. 将字符串调用为 std::string 以避免命名空间问题(编译器声明 'string is not a member of std')
  4. 改变编译器中的目标路径window(诚然,我不知道我在这里做什么,所以我可能需要一些建议...)
  5. 正在重新安装 Visual C++ redistributable(我试过 x86 和 x64...)
  6. 在新项目中重新启动我的代码
  7. 在arduino开发环境中重新启动我的代码(同样的错误,我认为这是一个系统问题)。

据我所知,我没有取得任何有意义的进展。以下是一些可能有用的其他屏幕截图:

如果有其他有用的信息,请告诉我。

... . . ...

所以,标准库是编译器提供的。对于最流行的库,如 gcc、clang 或 msvc,提供的库 99% 符合标准。但是一些微控制器编译器可能不支持 STL。检查 Arduino STL 对您的编译器的支持。据我所知,有一个官方的 Arduino IDE,尝试使用它