Eclipse IDE Arduino (Sloeber) c++类错误中的字符串没有命名类型

Eclipse IDE Arduino (Sloeber) C++ String in class error does not name a type

本文关键字:字符串 类型 错误 Arduino IDE Sloeber c++ Eclipse      更新时间:2023-10-16

在项目.ino文件中:

void loop()
{
    String stringOne = "Hello String";
}

然而,在一个类中我得到这些错误:

// MenuItem.h
//#include "String.h"   ====> Makes no difference if not commented
class MenuItem {
public:
    MenuItem();
private:
    String stringTwo;   ====> 'String' does not name a type
};

// MenuItem.cpp
//#include "String.h"    ====> Makes no difference if not commented
MenuItem::MenuItem() {
    stringTwo = "Goodbye String"; ===> 'stringTwo' was not declared in this scope
}

我已经尝试了#include的不同选项,<>而不是引号,没有.h.,我完全困惑了。谢谢。

Arduino的String类保存在WString.h和WString.cpp文件中。

你应该在你的。h文件中包含WString.h。Arduino IDE会自动为您的.ino文件执行此操作。