Mingw使用Windows API,但Windows没有提供符合要求的
vswprintf
函数来实现
to_string
,这应该归咎于Microsoft。如果您使用最新版本的mingw-w64 fork和未发布的4.8版本的GCC,则可以正常工作,但是主要的mingw32和GCC 4.7.1则无法使用。如果您愿意打补丁以尝试在您的实现中解决此问题,可以尝试在
http://tehsausage.com/mingw-to-string上提供的解决方案,但请仔细阅读其注意事项。
更新:似乎只有
std::to_wstring
受到破损的
vswprintf
函数的影响,因此我为GCC 4.9.3(及更高版本)进行了更改,将定义MinGW的
std::stoi
、
std::stod
、
std::to_string
等,并保持
to_wstring
未定义。如果您想自己编辑4.7.1头文件,这里是相关补丁:
--- 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
}
-#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
inline wstring
to_wstring(int __val)
@@ -3021,6 +3021,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
L"%Lf", __val);
}
#endif
+#endif
_GLIBCXX_END_NAMESPACE_VERSION
}