Using the "Array of Strings" example from the String Reference page gives C++ error

I have uses the Array of Strings Example from:

as a template, but the compiler sends back the following error on loading the sketch:

warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

now, the sketch runs; but what is this error, how can it be corrected, or is there a prefered method of creating the array of strings?

Can you show the word "error" in what you posted?

Make them const.

const char *myStrings[] = {"This is string 1", "This is string 2", "This is string 3",
                     "This is string 4", "This is string 5", "This is string 6"
                    };

It's a compiler setting that allows to treat this error as a warning.

The terms String and string mean different things and are not interchangable.

A string is a null terminated character array aka c_string.

A String is an object of the String class.

Thanks!

Whether this is flagged as a warning or an error will depend on how permissive the compiler options are set. Some board packages, such as for the ESP8266, use less permissive settings.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.