首先提出解决方案:
atoi
strtol
stoi
这几个有什么不同呢?下面测试对比。
C语言风格函数
atoi与strtol对比:
string str = "16s"; int a = atoi(str.c_str()); int b = strtol(str.c_str(), nullptr, 10);
输出:
atoi的结果为:16<

C语言风格函数
atoi与strtol对比:
string str = "16s"; int a = atoi(str.c_str()); int b = strtol(str.c_str(), nullptr, 10);
输出:
atoi的结果为:16<