std :: stoi不存在于g ++ 4.6.1在MinGW上 [英] std::stoi doesn't exist in g++ 4.6.1 on MinGW
问题描述
我尝试编译这个简单程序在IdeOne (使用gcc 4.5.1)和我的Linux计算机(使用4.6 .4):
#include< string>
#include< iostream>
int main(){
std :: cout< std :: stoi(32)<< std :: endl;
}
它完美编译,输出 32
。但是,当我试图在我的Windows计算机上编译它与MinGW和gcc 4.6.1,我得到这个错误:
test .cpp:在函数'int main()':
pre>
test.cpp:5:19:错误:'stoi'不是'std'的成员
std :: stoul
等也会发生同样的情况。std :: stoi
和家庭不存在于MinGW由于某些原因?我认为gcc on MinGW(sh | w)ould的行为与Linux上的一样。解决方案- 在Windows上的
vswprintf
的标准声明GNU标准库在此平台上定义_GLIBCXX_HAVE_BROKEN_VSWPRINTF
,从而禁用您尝试使用的转换函数。您可以在此处详细了解此问题和宏: http://gcc.gnu.org/bugzilla/show_bug .cgi?id = 37522 。
如果你愿意修改MinGW发布的头文件,你可以通过删除
... / lib / gcc / mingw32 / 4.6.1 / include / c ++ / bits的第2754行上的
,并将其添加回2905行到2965行(引用!定义(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)
basic_string.hstd :: vswprintf
的行)。您将无法使用std :: to_wstring
函数,但许多其他转换函数应该可用。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; }
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'
The same happens with
std::stoul
, etc. Doesstd::stoi
and family not exist in MinGW for some reason? I thought gcc on MinGW (sh|w)ould behave the same as on Linux.解决方案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.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 referencestd::vswprintf
). You won't be able to use thestd::to_wstring
functions, but many of the other conversion functions should be available.这篇关于std :: stoi不存在于g ++ 4.6.1在MinGW上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!