Arduino: WString.h is not compatible to c++11 range-based loop

Created on 8 Apr 2016  ·  3Comments  ·  Source: arduino/Arduino

I tried to use the new c++11 syntax with the default string class from arduino. Actually it fails because it has no begin or end.

Test-IDE: 1.6.8 (Win8.1 x64)
Board: Uno

Example code:

String temp = "abc";
for (auto tempchar : temp) {
    Serial.println(tempchar);
}

Error:

error: 'begin' was not declared in this scope
for (auto tempchar : temp) {
error: 'end' was not declared in this scope

Reference:
http://en.cppreference.com/w/cpp/language/range-for

Best

Most helpful comment

I have a PR hanging around: https://github.com/arduino/Arduino/pull/2179

I proposed this before C++11 was enabled (2014).
Would be nice to see this finally merged.

_While we're on the subject of the String class: https://github.com/arduino/Arduino/pull/3096_...

All 3 comments

This was already "discussed" somewhere else. No answer as I remember. I also suggest to add this feature.

I have a PR hanging around: https://github.com/arduino/Arduino/pull/2179

I proposed this before C++11 was enabled (2014).
Would be nice to see this finally merged.

_While we're on the subject of the String class: https://github.com/arduino/Arduino/pull/3096_...

Fixed with #2179

Was this page helpful?
0 / 5 - 0 ratings