废话不说,上代码
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
float fNum[2];
string str = "123, 345.6";
replace(str.begin(), str.end(), ',', ' ');
istringstream iss(str);
for(int i=0; i<2; i++)
{
iss >> fNum[i];
}
废话不说,上代码
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
float fNum[2];
string str = "123, 345.6";
replace(str.begin(), str.end(), ',', ' ');
istringstream iss(str);
for(int i=0; i<2; i++)
{
iss >> fNum[i];
}