2016-11-09 83 views
1

在项目.ino文件工作的:的Eclipse IDE的Arduino(Sloeber)C++字符串类错误没有指定类型

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.不同的选项我完全困惑。谢谢。

回答

1

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

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

+0

#include“WString.h”位于定义变量的.h文件中。 – user7117046