#include
#include
#include
#include
using namespace std;
int main()
{
string a = "112233";
char *b = new char[];
float c;
strcpy(b, a.c_str ());
c = atof(b);
cout << a << endl;
cout << c << endl;
cout << b << endl;
if(b!= NULL)
{
delete[] b; //我个人觉得释放时会出错,想好后告诉你
}
}
建议用double反正差不多
#include
#include
#include
#include
using namespace std;
int main()
{
string a = "112233";
double c;
c = atof(a.c_str());
cout << a << endl;
cout << c << endl;
}
#include
string str="123.4";
float f = atof(str.c_str());
如像没有提供此类的的转换.
多打几遍就变过来了,不信试试吧。