Home > Backend Development > C++ > body text

Why is `std::stoi` Missing in MinGW? A Look at the Underlying Problem and a Possible Solution.

Mary-Kate Olsen
Release: 2024-11-02 15:28:02
Original
135 people have browsed it

Why is `std::stoi` Missing in MinGW? A Look at the Underlying Problem and a Possible Solution.

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!