在项目.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文件执行此操作。