g++ 4.7.2 中缺少 std::stoi 吗? [英] std::stoi missing in g++ 4.7.2?

查看:24
本文介绍了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 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆