stoi() atoi() 转int
stoi() 和atoi() 函数将字符串转化为int型
区别是stoi的形参是const string*,而atoi的形参是const char*。c_str()的作用是将const string*转化为const char*
来自 <https://blog.csdn.net/Sarah_212/article/details/116720933>
string s1("1234567"); char* s2 = "1234567";
int a = stoi(s1); int b = atoi(s2); int c = atoi(s1.c_str()); cout << a << endl; cout << b << endl; cout << c << endl; |