user7117046 user7117046 -4 years ago 377
C++ Question

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

In the project

file this works:

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

However, in a class I get these errors:

// MenuItem.h
//#include "String.h" ====> Makes no difference if not commented
class MenuItem {
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

I've tried different option for the
instead of quotes and with without the
I'm totally confused. Thanks.

Answer Source

The String class for Arduino is held in the WString.h and WString.cpp files.

You should just include WString.h in your .h file. The Arduino IDE automatically does this for your .ino files.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download