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

**URL:** <https://forum.arduino.cc/t/using-the-array-of-strings-example-from-the-string-reference-page-gives-c-error/913886>\
**Category:** Programming\
**Created:** [October 11, 2021, 5:32pm UTC](https://forum.arduino.cc/t/using-the-array-of-strings-example-from-the-string-reference-page-gives-c-error/913886 "2021-10-11T17:32:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_armbruster](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@john\_armbruster](https://forum.arduino.cc/u/john_armbruster)\
**Post date:** [October 11, 2021, 5:32pm UTC](https://forum.arduino.cc/t/using-the-array-of-strings-example-from-the-string-reference-page-gives-c-error/913886/1 "2021-10-11T17:32:06Z")

</div>

I have uses the Array of Strings Example from:

> **[string - Arduino Reference](https://www.arduino.cc/reference/en/language/variables/data-types/string/)**
>
> The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.

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?

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [October 11, 2021, 5:43pm UTC](https://forum.arduino.cc/t/using-the-array-of-strings-example-from-the-string-reference-page-gives-c-error/913886/2 "2021-10-11T17:43:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [October 11, 2021, 6:01pm UTC](https://forum.arduino.cc/t/using-the-array-of-strings-example-from-the-string-reference-page-gives-c-error/913886/3 "2021-10-11T18:01:04Z")

</div>

> [@john\_armbruster](#):
>
> how can it be corrected, or is there a prefered method of creating the array of strings?

Make them _const_.

```c++
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.

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [October 11, 2021, 6:12pm UTC](https://forum.arduino.cc/t/using-the-array-of-strings-example-from-the-string-reference-page-gives-c-error/913886/4 "2021-10-11T18:12:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![john\_armbruster](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@john\_armbruster](https://forum.arduino.cc/u/john_armbruster)\
**Post date:** [October 11, 2021, 6:30pm UTC](https://forum.arduino.cc/t/using-the-array-of-strings-example-from-the-string-reference-page-gives-c-error/913886/5 "2021-10-11T18:30:44Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [October 11, 2021, 9:15pm UTC](https://forum.arduino.cc/t/using-the-array-of-strings-example-from-the-string-reference-page-gives-c-error/913886/6 "2021-10-11T21:15:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [April 9, 2022, 9:15pm UTC](https://forum.arduino.cc/t/using-the-array-of-strings-example-from-the-string-reference-page-gives-c-error/913886/7 "2022-04-09T21:15:06Z")

</div>

Closed on April 9, 2022, 9:15pm UTC

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