Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

mingw

#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 which is running MinGW GCC 4.7.2. It gives me this error:

enter image description here

What am I doing wrong, I got this from cppreference. Its the exact same code. And its a different error from the one described here.

like image 590
Games Brainiac Avatar asked Apr 21 '13 14:04

Games Brainiac


1 Answers

It seems your MinGW needs a patch: Enabling string conversion functions in MinGW

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

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

In above link, there is a .zip file, 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 os_defines.h 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 with the correct version number)
like image 170
masoud Avatar answered Oct 15 '22 13:10

masoud