Mingw使用Windows API,而Windows不提供vswprintf
函數的合規版本,用於實現to_string
,這歸咎於微軟。
如果你使用MinGW的-W64叉和未發佈的4.8版本的GCC的(非常)最新版本,然後它會工作,但你的運氣失控與主要的mingw32和GCC 4.7.1
如果你願意修補你的實現,你可以嘗試在http://tehsausage.com/mingw-to-string給出的解決方案,但仔細閱讀注意事項。
更新:
似乎只有std::to_wstring
由破vswprintf
功能的影響,所以我做了GCC 4.9.3(及更高版本),這將定義std::stoi
,std::stod
,std::to_string
變化等MinGW,只是離開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
} // 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
你申請這個補丁?你會給我錯誤報告或補丁提交的鏈接嗎? –
https://gcc.gnu.org/PR37522和https://gcc.gnu.org/r219019雖然更改測試是一個錯誤(導致https://gcc.gnu.org/PR64438),並且我恢復了https://gcc.gnu.org/r219146 –
非常感謝 –