C++ std:stoi在g+中缺失+;4.7.2?

C++ std:stoi在g+中缺失+;4.7.2?,c++,compiler-errors,g++,std,c++-standard-library,C++,Compiler Errors,G++,Std,C++ Standard Library,当我尝试使用std::stoi并尝试编译它时,会收到错误消息“stoi不是std的成员”。我在命令行中使用g++4.7.2,这样就不会出现IDE错误,我已经准备好了所有的include,g++4.7.2默认使用c++11。如果有帮助的话,我的操作系统是Ubuntu 12.10。有什么我没有配置的吗 #include <iostream> #include <string> using namespace std; int main(){ string theAns

当我尝试使用std::stoi并尝试编译它时,会收到错误消息“stoi不是std的成员”。我在命令行中使用g++4.7.2,这样就不会出现IDE错误,我已经准备好了所有的include,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, 0, 10);

  cout << "The answer to everything is " << ans << endl;
}
#包括
#包括
使用名称空间std;
int main(){
字符串theAnswer=“42”;
int ans=std::stoi(答案为0,10);
cout
std::stoi()
在中是新的,因此您必须确保使用以下工具编译它:

g++ -std=c++11 example.cpp


<>旧版本的C++编译器不支持STOI。对于旧版本,可以使用以下代码片段将字符串转换为整数。
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main() {
    string input;
    cin >> input;
    int s = std::atoi(input.c_str());
    cout<<s<<endl;
    return 0;
}
#包括
#包括
#包括
使用名称空间std;
int main(){
字符串输入;
cin>>输入;
ints=std::atoi(input.c_str());

如果需要实际帮助,您可能必须显示实际的代码。但是,代码很好。您希望我显示什么代码?对std::stoi的完全有效的调用不起作用?也不起作用。此外,-std=c++11在默认情况下似乎处于启用状态。我正在处理的代码的一个编译器警告也说明了这一点(注意,上面的代码只是告诉我stoi不是stoi的成员,所以问题不在于我的代码)我把你的代码保存为Expul.CPP,并尝试:<代码> G+++示例.CPP < /Cord>并得到了你提到的错误。当我添加了<代码> -ST+C++ 11 < /> >或<> > -STD= C++ +0x。它编译并运行得很好。我的笔记本上的G+Mman页面说GnU++ 98是C++的默认方言。在指定要编译的源代码的文件名之前,必须设置ag…我不知道这一点,而且我在任何地方都没有看到任何指出这一事实的东西。案例结束。这对我来说也是新闻,很高兴你把它整理好了!你说的“必须设置标志”是什么意思?什么标志?我遇到了一个类似的问题,出现了错误:“atoi”不是带有“g++-std=c++98”的“std”的成员
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main() {
    string input;
    cin >> input;
    int s = std::atoi(input.c_str());
    cout<<s<<endl;
    return 0;
}