std::stoi 在 MinGW 上的 g++ 4.6.1 中不存在

2023-04-11C/C++开发问题
2

本文介绍了std::stoi 在 MinGW 上的 g++ 4.6.1 中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我尝试在在 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 中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&amp;()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6