stoi and std::to_string on mingw 4.7.1
stoi and std::to_string on mingw 4.7.1
我想把我的C++11程序移植到windows,但在第4.7.1页中似乎没有实现stoi和std::to_string。我知道有人问过我,有一个编辑一些标题的解决方案,但在我的mingw版本(与codelite一起发货的4.7.1)中,标题是不同的,并且没有我必须移动的确切行(可能是因为答案是针对mingw 4.6)
所以我的问题是如何在mingw 4.7上获得这些函数?有什么指南可以在4.7中更改标题,或者它可能会包含在4.8中吗?
当然还有boost::lexical_cast,但我想保持代码不变,所以我正在寻找如何在mingw中启用这些函数的解决方案。
也许有一些自定义的mingw发行版支持这些功能?
Mingw使用Windows API,而Windows没有提供用于实现to_string
的vswprintf
函数的一致版本,这要归咎于Microsoft。
如果你使用(非常)新版本的mingw-w64 fork和未发布的GCC 4.8版本,那么它会起作用,但你对主要的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
} // 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
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 瓦尔格林德:数学函数"Conditional jump or move depends on uninitialised value(s)"
- 如何将C++中的库和头与MinGW一起使用
- 为什么与常规GCC不同,即使有"学究性错误",MinGW-GCC也能容忍丢失的返回类型
- 无法在windows上使用mingw将sqlite3与c连接
- MinGw 无法从 cmake 编译测试文件
- MSYS2 MinGW程序包中缺少grpc_cpp_plugin协议
- Mingw-64 在构建和安装后不会编译 openCV 代码
- 安装MinGW后C++编译器不起作用?
- 当我尝试通过 mingw 使用 CMake 和 SFML 库编译项目时出错
- 如何在 Linux for Windows 上通过 MinGW 构建静态 ICU 的 Boost
- 使用 MinGW 在 Windows 上安装 GMP 时出错
- VSCode - C++ - MinGW 编译器的问题
- Boost::process on Windows - with MinGW?
- CMake & MinGW Compileilation on Windows,无需 -G "MinGW Makefiles"标志
- InterlockedOr8 on gcc MinGW
- Qt5 Project on Windows with MinGW
- Qt 5.1.0 on Windows 使用 minGW 4.8,需要很长时间才能调试
- Using Clang on Mingw 64bit
- stoi and std::to_string on mingw 4.7.1