我尝试在在 IdeOne(使用 gcc 4.5.1)和我的 Linux 计算机(使用类似 4.6.4):
I tried compiling this simple program on IdeOne (which uses gcc 4.5.1) and on my Linux computer (which uses something like 4.6.4):
#include <string>
#include <iostream>
int main() {
std::cout << std::stoi("32") << std::endl;
}
它完美地编译并输出32
.但是,当我尝试使用 MinGW 和 gcc 4.6.1 在我的 Windows 计算机上编译它时,出现此错误:
And it compiles perfectly and outputs 32
. However, when I try to compile it on my windows computer with MinGW and gcc 4.6.1, I get this error:
test.cpp: In function 'int main()':
test.cpp:5:19: error: 'stoi' is not a member of 'std'
std::stoul
等也会发生同样的情况.std::stoi
和 family 是否出于某种原因在 MinGW 中不存在?我认为 MinGW (sh|w) 上的 gcc 的行为与 Linux 上的一样.
The same happens with std::stoul
, etc. Does std::stoi
and family not exist in MinGW for some reason? I thought gcc on MinGW (sh|w)ould behave the same as on Linux.
这是 Windows 上 vswprintf
非标准声明的结果.GNU 标准库在此平台上定义了 _GLIBCXX_HAVE_BROKEN_VSWPRINTF
,从而禁用您尝试使用的转换函数.您可以在此处阅读有关此问题和宏的更多信息:http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37522.
This is a result of a non-standard declaration of vswprintf
on Windows. The GNU Standard Library defines _GLIBCXX_HAVE_BROKEN_VSWPRINTF
on this platform, which in turn disables the conversion functions you're attempting to use. You can read more about this issue and macro here: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37522.
如果您愿意修改与 MinGW 一起分发的头文件,您可以通过删除 !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)
宏在 .. 的第 2754 行来解决这个问题../lib/gcc/mingw32/4.6.1/include/c++/bits/basic_string.h
,并将其添加回第 2905 到 2965 行(引用 std::vswprintf
).您将无法使用 std::to_wstring
函数,但许多其他转换函数应该可用.
If you're willing to modify the header files distributed with MinGW, you may be able to work around this by removing the !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)
macro on line 2754 of .../lib/gcc/mingw32/4.6.1/include/c++/bits/basic_string.h
, and adding it back around lines 2905 to 2965 (the lines that reference std::vswprintf
). You won't be able to use the std::to_wstring
functions, but many of the other conversion functions should be available.
这篇关于std::stoi 在 MinGW 上的 g++ 4.6.1 中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!