g++ (GCC) 4.8.2 -libstdc++.a --> gcc-g++-4.8.2-1 尝-6ren">
gpt4 book ai didi

c++11 - cygwin g++ std::stoi "error: ‘stoi’ 不是“std”的成员

转载 作者:行者123 更新时间:2023-12-02 22:11:53 26 4
gpt4 key购买 nike

我有:

-Windows 7/32 位上的 cygwin 1.7.25

-g++ --版本 --> g++ (GCC) 4.8.2

-libstdc++.a --> gcc-g++-4.8.2-1

尝试制作一个c++ Hello World :

#include <string>

int main()
{
std::string s = "123";
int i = std::stoi(s);
}

编译给出:

$ g++ -std=c++11 main.cpp
main.cpp: In function ‘int main()’:
main.cpp:6:10: error: ‘stoi’ is not a member of ‘std’
int i = std::stoi(s);

我搜索了几个小时,但仍然找不到解决方案。这里有什么问题吗?

最佳答案

这是一个错误,可能是某些库代码到 cygwin 的不完整移植(这是 cplusplus11 的功能)——毕竟有些东西必须更改。请务必报告。

解决方案当然很简单:#include <cstdlib> strtol(s.c_str(),0,10);

www.cplusplus.com/.../strtol

还提到了类似的 mingw bug here

std::stoi doesn't exist in g++ 4.6.1 on MinGW

关于c++11 - cygwin g++ std::stoi "error: ‘stoi’ 不是“std”的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20145488/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com