加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – std :: stoi在4.7.2中缺少?

发布时间:2020-12-16 05:35:50 所属栏目:百科 来源:网络整理
导读:当我尝试使用std :: stoi并尝试编译时,我收到错误消息“stoi不是std的成员”.我从命令行使用g 4.7.2,所以它不能是IDE错误,我有我的所有包含在顺序,而g 4.7.2默认使用c 11.如果有帮助,我的操作系统是Ubuntu 12.10.有没有我没有配置的东西? #include iostream
当我尝试使用std :: stoi并尝试编译时,我收到错误消息“stoi不是std的成员”.我从命令行使用g 4.7.2,所以它不能是IDE错误,我有我的所有包含在顺序,而g 4.7.2默认使用c 11.如果有帮助,我的操作系统是Ubuntu 12.10.有没有我没有配置的东西?
#include <iostream>
#include <string>

using namespace std;

int main(){
  string theAnswer = "42";
  int ans = std::stoi(theAnswer,10);

  cout << "The answer to everything is " << ans << endl;
}

不会编译但没有任何错误.

解决方法

std :: stoi()是 C++11中的新功能,所以你必须确保你编译它:
g++ -std=c++11 example.cpp

要么

g++ -std=c++0x example.cpp

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读