使用 Atom 编译器,编译c++程序,该程序中使用了 stoi() 函数,编译器会报错,提示 error: 'stoi' was not declared in this scope ,使用的是万能头文件,不知道该怎么处理了,求各位大佬解答!ORZ
stoi atoi __atoi 等等这些函数都不是标准库的函数,和你的编译器有关,你查查文档,你的编译器支持哪一种。
或者自己写一个
#include <iostream>
#include <string>
using namespace std;
int stoi(string s)
{
int base = 0;
int sign = 1;
const char * s1 = s.c_str();
if (*s1 == '-') { sign = -1; s1++; }
while (*s1 != '\0')
{
base = base * 10;
base = base + *s1 - '0';
s1++;
}
return base * sign;
}
int main()
{
string s = "1010";
cout << stoi(s);
return 0;
}
采纳
。