这段代码有什么问题?我需要将字符串转换为浮点数。m2 在m2.length中有错误
#include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
int main()
{
float v2;
char *m2 = "1 23 45 6";
for (int i = 0; i < m2.length(); i++) //to convert every element in m2 into float
{
v2 = atof(&m2[i]);
}
printf("%.2f", v2);
system("pause");
return 0;
}