std::stoi missing in g++ 4.7.2?(g++ 4.7.2 中缺少 std::stoi 吗?)
问题描述
当我尝试使用 std::stoi 并尝试编译它时,我收到错误消息stoi 不是 std 的成员".我正在从命令行使用 g++ 4.7.2,所以它不会是 IDE 错误,我按顺序排列了所有包含,并且 g++4.7.2 默认使用 c++11.如果有帮助,我的操作系统是 Ubuntu 12.10.有什么我没有配置的吗?
I get the error message "stoi is not a member of std" when I try to use std::stoi and try to compile it. I'm using g++ 4.7.2 from the command line so it can't be IDE error, I have all my includes in order, and g++4.7.2 defaults to using c++11. If it helps, my OS is Ubuntu 12.10. Is there something I haven't configured?
#include <iostream>
#include <string>
using namespace std;
int main(){
string theAnswer = "42";
int ans = std::stoi(theAnswer, 0, 10);
cout << "The answer to everything is " << ans << endl;
}
不会编译.不过也没什么不好.
Will not compile. But there's nothing wrong with it.
推荐答案
std::stoi() 是 C++11 所以你必须确保你编译它:
std::stoi() is new in C++11 so you have to make sure you compile it with:
g++ -std=c++11 example.cpp
或
g++ -std=c++0x example.cpp
这篇关于g++ 4.7.2 中缺少 std::stoi 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:g++ 4.7.2 中缺少 std::stoi 吗?
基础教程推荐
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- c++ STL设置差异 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
