to_string

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

to_string

Postby permal » Mon Aug 07, 2017 8:16 am

Hi,

std::to_string(...) is supposed be included in C++11 via <string.h>, but it seems to not be included when compiling with the Xtensa port of GCC. Am I missing something, or is it actually not available? If not, can it be made available?

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: to_string

Postby ESP_igrr » Mon Aug 07, 2017 9:54 am

This incompatibility between libstdc++ and newlib seems to be discussed here: https://gcc.gnu.org/ml/libstdc++/2013-10/msg00245.html

It seems that rebuilding libstdc++ is required, and `__STDC_VERSION__` has to be tweaked while libstdc++ is going through ./configure step, so that newlib provides vprintf declaration.

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: to_string

Postby permal » Mon Aug 07, 2017 12:58 pm

Oh, what a hassle :P

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: to_string

Postby kolban » Mon Aug 07, 2017 2:16 pm

As a possible alternative, one might be able to use std::stringstream.

Once can then perform logic similar to:

std::string stream ss << "Hello world" << myDouble << " " << myInt;
std::string s = ss.str();
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: to_string

Postby permal » Mon Aug 07, 2017 3:04 pm

Yes, stringstream is an alternative, though it is rather heavy just to convert a single integer into an alphanumeric.

Who is online

Users browsing this forum: Google [Bot] and 111 guests