C++11 Support. Function stoi() error

Nelson32
Posts: 1
Joined: Sun Oct 22, 2017 11:44 pm

C++11 Support. Function stoi() error

Postby Nelson32 » Mon Oct 23, 2017 12:14 am

Greetings.
I'm working on an application for ESP32 in C ++ using Eclipse. I use strings and need to use the "stoi()" function (c ++ 11), however when I use it I get the following

Code: Select all

error: 'stoi' was not declared in this scope
. Will it be supported by c ++ 11? How can I solve that?

Thanks

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

Re: C++11 Support. Function stoi() error

Postby kolban » Mon Oct 23, 2017 8:27 am

One possibility is to use atoi...

Code: Select all

std::string x = "123";
int i = atoi(x.c_str());
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: C++11 Support. Function stoi() error

Postby mzimmers » Thu Jun 28, 2018 5:01 pm

I know this is an old thread, but I just encountered the problem as well. Seems to stem from the fact that stoi is conditionally compiled based on support for wide characters, which mingw32 doesn't have.
http://www.mingw.org/wiki/The_linker_co ... references
Looks like using atoi is the best bet...

User avatar
thefury
Posts: 20
Joined: Thu Sep 05, 2019 5:25 pm

Re: C++11 Support. Function stoi() error

Postby thefury » Thu Sep 05, 2019 5:29 pm

I was able to resolve it by defining _GLIBCXX_USE_C99

Either this in the Makefile:
  1. CXXFLAGS += -D_GLIBCXX_USE_C99
or this at the top of a cpp or h file where needed:
  1. #define _GLIBCXX_USE_C99

Who is online

Users browsing this forum: Bing [Bot] and 99 guests