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 吗?
基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
