C语言读科学计数法文本
(2012-11-30 09:46:13)
标签:
vc科学计数法c语言sscanfatofit |
可以使用两种方法很方便的读取科学计数法文本并转化为浮点数,分别是sscanf和atof。
因为以下例程是使用VC2008实现的,因此分别变形为它们各自的宽字符版本:swscanf和_wtof。
必须要注意的是,使用sscanf读取科学计数法时,必须使用%lf,而不是%f。
CString str = _T("1.9626E+004
2.6789E+004");
{
double f1, f2;
swscanf(str, _T("%lf %lf"), &f1, &f2);
TRACE(_T("%f %f\r\n"), f1, f2);
}
{
TCHAR str1[1024], str2[1024];
swscanf(str, _T("%s %s"), str1, str2);
double f1 = _wtof(str1);
double f2 = _wtof(str2);
TRACE(_T("%f %f\r\n"), f1, f2);
}
{
double f1, f2;
swscanf(str, _T("%lf %lf"), &f1, &f2);
TRACE(_T("%f %f\r\n"), f1, f2);
}
{
TCHAR str1[1024], str2[1024];
swscanf(str, _T("%s %s"), str1, str2);
double f1 = _wtof(str1);
double f2 = _wtof(str2);
TRACE(_T("%f %f\r\n"), f1, f2);
}
前一篇:一维vector整形成二维