Problems with std::stoi, not working on MinGW GCC 4.7.2
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)
std::stoi doesn't exist in g++ 4.6.1 on MinGW
This is a result of a non-standard declaration of vswprintf
on Windows. The GNU Standard Library defines _GLIBCXX_HAVE_BROKEN_VSWPRINTF
on this platform, which in turn disables the conversion functions you're attempting to use. You can read more about this issue and macro here: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37522.
If you're willing to modify the header files distributed with MinGW, you may be able to work around this by removing the !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)
macro on line 2754 of .../lib/gcc/mingw32/4.6.1/include/c++/bits/basic_string.h
, and adding it back around lines 2905 to 2965 (the lines that reference std::vswprintf
). You won't be able to use the std::to_wstring
functions, but many of the other conversion functions should be available.
MinGW g++ cannot find std::stof
Not sure about exact problem, but check mingw-w64 they have gcc 4.9.2 for now. It compiles your code just well. (But since the mingw-w64 project on sourceforge.net is moving to mingw-w64.org it's better to use mingw-w64.org)
Despite of it's name it provides compilers for both x86 and x64 targets.
Probably this should be a comment, not an answer.
std::stod is not a member of std
std::stod
is only available if you are at least using std=c++11
to compile. Therefore, when you compile, just add the flag -std=c++11
and you will be able to use stod
Error with stoi and debugged with gdb
Yeah, I think you're doing something pretty silly. You probably compiled the first code, which doesn't have the std::cout
statement, and you probably executed the compilation steps without -std=c++11
which would result in std::stoi
not being included beecause std::stoi
is from C++11 and onward. The result is still the old executable which prints out nothing.
Recompile using -std=c++11
and make sure that you saved your file correctly. Your code clearly works.
Note: the vanilla port of GCC of MinGW on Windows is flawed and has a few bugs related to C++11 and onwards; using MinGW-w64, if you ever decide to compile on Windows, can help the problem.
Related Topics
Sending an Email from a C/C++ Program in Linux
Openprocess/Readprocessmemory/Writeprocessmemory/Closehandle Equivalent
End of File(Eof) of Standard Input Stream (Stdin)
Why Use Functors Over Functions
Memset() or Value Initialization to Zero Out a Struct
Emulate "Double" Using 2 "Float"S
Why Can't We Pass Arrays to Function by Value
Determine If Linux or Windows in C++
Pthread Condition Variables Not Signalling Even Though Set to Pthread_Process_Shared
C++ Delete Vector, Objects, Free Memory
Is String::C_Str() No Longer Null Terminated in C++11
How Do Exceptions Work (Behind the Scenes) in C++
Is the Memory Allocated for Struct Members Continguous? What If a Struct Member Is an Array