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;

 

posted @ 2022-08-30 21:35  atomxing  阅读(19)  评论(0编辑  收藏  举报