一、string转为int : string是个类,里面有个c_str()成员函数,返回const char*,atoi函数把一个字符串传唤为int。 atoi()将字符串转换成整型数的函数 例如: string s = "1234"; n = atoi(s.c_str());
二、string转为float 原理基本上和string转为nt一样,只是函数不同。 atof()将字符串转换成浮点数的函数 例如: string s=“1234”;
|
一、string转为int : string是个类,里面有个c_str()成员函数,返回const char*,atoi函数把一个字符串传唤为int。 atoi()将字符串转换成整型数的函数 例如: string s = "1234"; n = atoi(s.c_str());
二、string转为float 原理基本上和string转为nt一样,只是函数不同。 atof()将字符串转换成浮点数的函数 例如: string s=“1234”;
|