Page 1 of 1

C++11 Support. Function stoi() error

Posted: Mon Oct 23, 2017 12:14 am
by Nelson32
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

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

Posted: Mon Oct 23, 2017 8:27 am
by kolban
One possibility is to use atoi...

Code: Select all

std::string x = "123";
int i = atoi(x.c_str());

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

Posted: Thu Jun 28, 2018 5:01 pm
by mzimmers
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...

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

Posted: Thu Sep 05, 2019 5:29 pm
by thefury
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