C++将string转化为int或者double(转载)

原文链接:https://blog.csdn.net/wusecaiyun/article/details/48049439

化为int,有两种方式:

string s = “123”;

int c = atoi(s.c_str());

或者

int c = stoi(s);

将string转化为double,也是两种方式。

string s = “123.5”;

double c = atof(s.c_str())

或者

double c = stod(s);

发布了104 篇原创文章 · 获赞 97 · 访问量 4515

猜你喜欢

转载自blog.csdn.net/TK_wang_/article/details/104920131
今日推荐