code doesn't compile

I'm using CodeBlocks, with GNU GCC compiler (ver. 4.9.2). In Global Compiler settings the "Have a g++ follow the C++ ISO C++ language standard [-std=c++11]" flag is ticked.

I'd like using function stoi() (header <string> is included). Compiling is unsuccessful with error message "error 'stoi'was not declared in this scope"

How to get rid of this error?
You need to upgrade your compiler.
What version of compiler do I have to use? The reference of the compiler https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc.pdf says this version should know the C++11 standard.
I assume you use MinGW (GCC fork for Windows) and that version did unfortunately not support stoi and other similar string functions. The original mingw project at mingw.org seems kind of dead because it hasn't been updated in many years. The latest version of Code::Blocks comes with TDM-GCC but I have no idea if it supports stoi or not.

For the most up-to-date version GCC on Windows I think you should use Mingw-w64 (another MinGW fork). It should support stoi as far as I have heard. https://mingw-w64.org/
Last edited on
I think that the best choice for me is leave the stoi() choosing an other way to turn my strings into integers. :-)
if your compiler doesn't have anything else available, you can drop to C for a moment:

string s = "1234";
int i = atoi(s.c_str());

It has its own unique set of issues but I use g++ on windows via cygwin. It seems to be more or less up to date. Certainly has 11 features, not sure if it has ALL the 17s or not.
Last edited on
Registered users can post here. Sign in or register to post.