Stoi and std :: to_string on mingw 4.7.1

Well, I wanted to port my C ++ 11 program to Windows, but it seems like no stoi and std :: to_string are implemented in mingw 4.7.1. I know this was asked and there was a solution to edit some title, but in my version of mingw (4.7.1, supplied with the code name) the title is different and there are no exact lines that I should move (probably because the answer was for mingw 4.6).

So my question is, how can I get these features in mingw 4.7? Is there any guidance to change the title in 4.7 or maybe it will be included in 4.8?

Of course there is boost :: lexical_cast, but I would like to leave my code unchanged, so I'm looking for a solution on how to enable these features in mingw.

Maybe there is some custom mingw distribution that comes with support for these features?

+3


source to share


1 answer


Mingw uses the Windows API and Windows does not provide a compatible version of the function vswprintf

used to implement to_string

, Microsoft blames.

If you are using a (very) recent fork of mingw-w64 and the unreleased 4.8 version of GCC then it will work, but you have no luck with the mainstream mingw32 and GCC 4.7.1

If you're ready to fix your implementation, you can try the solution listed at http://tehsausage.com/mingw-to-string , but read the caveats carefully.

Update:



It seems that only std::to_wstring

exposed to impaired function vswprintf

, so I made changes for GCC 4.9.3 (or later) that will define std::stoi

, std::stod

, std::to_string

etc. for MinGW, and just leave it to_wstring

undefined.

If you'd like to edit the 4.7.1 header yourself, here's the relevant patch:

--- a/home/jwakely/gcc/4.7.1/include/c++/4.7.1/bits/basic_string.h
+++ b/home/jwakely/gcc/4.7.1/include/c++/4.7.1/bits/basic_string.h.fix
@@ -2808,8 +2808,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace

-#if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99) \
-     && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
+#if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99)

 #include <ext/string_conversions.h>

@@ -2959,6 +2958,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   stold(const wstring& __str, size_t* __idx = 0)
   { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }

+#ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
   // DR 1261.
   inline wstring
   to_wstring(int __val)
@@ -3021,6 +3021,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                                            L"%Lf", __val);
   }
 #endif
+#endif

 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace

      

+6


source







All Articles