首页 > 其他分享 >stoi() atoi() 转int

stoi() atoi() 转int

时间:2022-08-30 21:47:17浏览次数:60  
标签:const cout int char atoi stoi

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;

 

标签:const,cout,int,char,atoi,stoi
From: https://www.cnblogs.com/libxing/p/16640929.html

相关文章