用c++实现字符串数转化成整型

来源:百度知道 编辑:UC知道 时间:2024/06/22 23:58:51
要求不能用itao函数

atoi()

新的C++标准使用istringstream流,即:
istringstream strin("12345 2.3");
int a;
double b;
strin>>a>>b;
头文件 sstream

老标准使用istrstream流,即
istrstream strin("12345 2.3");
int a;
double b;
strin>>a>>b;
头strstream

最好是用C流,即
char str[] = "123 3.14";
int a;
double b;
sscanf(str, "%d %lf", &a, &b);