bool CTextFormat::ToFloat(const char* fpath, char delim)
{
fstream file(fpath, ios::in);
stringstream sBuf;
string str;
float f1[20][3] = {0};
float f2[20][3] = {0};
int count = 0;
if( !file )
{
// TODO:
return false;
}
while( getline(file, str) )
{
if( *(str.c_str()) == NULL ) break;
sBuf.str(str);
for(int i=0; i<3; )
{
if( sBuf >> f1[count][i] )
i++;
else
return false;
}
count++;
str.clear();
sBuf.clear();
}
for( int i=0; i<20; i++)
cout << f1[i][0] << f1[i][1] << f1[i][2] << endl;
count = 0;
while( getline(file, str) )
{
if( *(str.c_str()) == NULL ) break;
sBuf.str(str);
for(int i=0; i<3; )
{
if( sBuf >> f2[count][i] )
i++;
else
return false;
}
count++;
str.clear();
sBuf.clear();
}
for( int i=0; i<20; i++)
cout << f2[i][0] << f2[i][1] << f2[i][2] << endl;
file.close();
}
IOStream
最新推荐文章于 2025-12-02 07:04:44 发布
本文介绍了一个名为boolCTextFormat::ToFloat的方法,该方法从指定路径的文件中读取数据,并使用流和字符串流将每行数据中的浮点数提取到二维数组中。同时展示了如何通过两次遍历文件来分别处理两组数据。
2095

被折叠的 条评论
为什么被折叠?



