使用 Atom 编译器,编译c++程序,该程序中使用了 stoi() 函数,编译器会报错,提示 error: 'stoi' was not declared in this scope ,使用的是万能头文件,不知道该怎么处理了,求各位大佬解答!ORZ
1条回答 默认 最新
- threenewbee 2020-01-30 10:48关注
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; }
问题解决的话,请点下
采纳
。解决 2无用
悬赏问题
- ¥15 程序不包含适用于入口点的静态Main方法
- ¥15 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记