Problems with std :: stoi not working on MinGW GCC 4.7.2

#include <iostream> #include <string> int main() { std::string test = "45"; int myint = stoi(test); std::cout << myint << '\n'; } 

I tried this code on my computer that works with MinGW GCC 4.7.2. This gives me this error:

enter image description here

What am I doing wrong, I got this from cppreference . Its exact code. And this is another mistake from the one described here .

+8
c ++ mingw
source share
2 answers

Your MinGW seems to need a patch: Enabling string conversion functions in MinGW

This patch includes the following list of C ++ 11 functions and templates in the std namespace:

stoi, stol, stoul, stoll, stof, stod, stold, to_string, to_wstring

There is a .zip file in the link above, download it and

  • Copy wchar.h and stdio.h from the include directory in the zip file to the following directory (overwrite): C: \ mingw \ include (replace C: \ mingw \ with the appropriate directory)
  • Copy the os_defines.h file to the following directory (overwrite): C: \ mingw \ lib \ gcc \ mingw32 \ 4.7.0 \ include \ C ++ \ mingw32 \ bits (replace C: \ mingw \ with the appropriate directory) (replace 4.7 .0 to the correct version number)
+14
source share

Another solution is to use MinGW-w64 , which works correctly out of the box. This is the MinGW plug that can create both 32-bit and 64-bit builds.

0
source share

All Articles