【发布时间】:2014-02-16 17:08:52
【问题描述】:
我正在尝试获取一个字符串并将其解析为一个 int。我已经阅读了很多答案,似乎使用stoi 是最新的方法。在我看来stoi 使用std,但我得到Function 'stoi' could not be resolved 绝望using namespace std;
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include<stdlib.h>
using namespace std;
int main(int argc, char* argv[]) {
string line = "";
string five = "5";
int number = stoi(five); //Error here with stoi
return 0;
}
任何想法是什么原因造成的?
更新:
我正在使用 Eclipse。我的标志是:-c -fmessage-length=0 -std=c++11
【问题讨论】:
-
你忘了告诉我们你的编译器是什么,以及你是如何编译这个程序的。
-
plab 很好找 plab。好眼力!在你的答案中张贴一个大的绿色复选标记
-
你还没有告诉我们什么编译器,什么版本,或者类似的东西。请养成精确的习惯。
-
我个人喜欢这种情况下的字符串流。
istringstream iss(five); iss >> number;
标签: c++ parsing c++11 namespaces std