微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

原文地址:https://www.jb51.cc/c/114297.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐