stoi和std :: to_string on mingw 4.7.1 [英] stoi and std::to_string on mingw 4.7.1

查看:239
本文介绍了stoi和std :: to_string on mingw 4.7.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想把我的C ++ 11程序到Windows,但似乎在mingw 4.7.1没有stoi和std :: to_string实现。我知道它已被问及有一个解决方案来编辑​​一些标题,但在我的mingw版本(4.7.1随附codelite)标题是不同的,没有精确的行,我必须移动(可能是因为答案对于mingw 4.6)。

Well I wanted to port my C++11 programm to windows, but it seems in mingw 4.7.1 there is no stoi and std::to_string implemented. I know it has been asked and there was a solution to edit some header, but in my mingw version (4.7.1 shipped with codelite) the header is different and there are no the exact lines I have to move (probably because the answer was for mingw 4.6).

所以我的问题是如何获得这些功能在mingw 4.7?
有没有任何指南在4.7中改变header或者也许它会包含在4.8?

So my question is how can I get these functions on mingw 4.7? Is there any guide what to change in header in 4.7 or maybe it will be included in 4.8?

当然还有boost :: lexical_cast,我希望保持我的代码不变,所以我正在寻找解决方案如何在mingw中启用这些功能。

Of course there is boost::lexical_cast, but I'd like to keep my code unchanged, so I'm looking for solution how to enable these functions in mingw.

也许有一些自定义的mingw发行版带有支持对于这些功能?

Maybe there is some custom mingw distro which comes with support for these functions?

推荐答案

Mingw使用Windows API,Windows不提供符合版本的 vswprintf 函数用于实现 to_string ,微软指责。

Mingw uses the Windows API, and Windows doesn't provide a conforming version of the vswprintf function used to implement to_string, blame Microsoft.

一个(非常)最新版本的mingw-w64 fork和未发布的4.8版本的GCC然后它会工作,但你运气主要mingw32和GCC 4.7.1

If you use a (very) recent version of the mingw-w64 fork and the unreleased 4.8 version of GCC then it will work, but you're outta luck with the main mingw32 and GCC 4.7.1

如果您愿意修补您的实施,可以尝试 http:// tehsausage .com / mingw-to-string ,但请仔细阅读注意事项。

If you're willing to patch your implementation you could try the solution given at http://tehsausage.com/mingw-to-string but read the caveats carefully.

更新:

似乎只有 std :: to_wstring 受破坏的 vswprintf 函数的影响,因此我对GCC 4.9.3(和更高版本)做了一个更改,它将定义 std :: stoi std :: stod to_wstring 未定义

It seems that only std::to_wstring is affected by the broken vswprintf function, so I've made a change for GCC 4.9.3 (and later versions) which will define std::stoi, std::stod, std::to_string etc. for MinGW, and just leave to_wstring undefined.

如果你想自己编辑4.7.1标题,这里是相关的补丁:

If you want 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

这篇关于stoi和std :: to_string on mingw 4.7.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆