std::stoi Error in MinGW: A Dependency Dilemma
Unable to compile using std::stoi in MinGW? Find out the surprising reason and potential workaround.
Issue:
Attempts to use functions like std::stoi trigger errors in MinGW with gcc 4.6.1, specifically "error: 'stoi' is not a member of 'std'". These functions exist in more recent versions of the GNU Standard Library (GSL), but why not in MinGW?
Answer:
The culprit is a non-standard declaration in Windows. GSL defines _GLIBCXX_HAVE_BROKEN_VSWPRINTF on this platform, which disables the conversion functions std::stoi and others.
Workaround:
A possible solution is to modify the GSL header files. Remove the !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF) macro from line 2754 of .../lib/gcc/mingw32/4.6.1/include/c /bits/basic_string.h. Additionally, add the macro back around lines 2905 to 2965, which reference std::vswprintf.
Implications:
This workaround disables std::to_wstring functions but allows the use of other conversion functions. Note that this is a non-standard modification and may have unforeseen consequences.
The above is the detailed content of Why is `std::stoi` Missing in MinGW? A Look at the Underlying Problem and a Possible Solution.. For more information, please follow other related articles on the PHP Chinese website!