C++将string转化为int或者double

来源:互联网 发布:t-sql取别名 编辑:程序博客网 时间:2024/05/18 03:25

转化为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);


0 0
原创粉丝点击