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

查看:311
本文介绍了std :: stoi在g ++ 4.7.2中缺少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用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;
}

无法编译。

推荐答案

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

这篇关于std :: stoi在g ++ 4.7.2中缺少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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