首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

用VC中的文件操作实现读取文本数据有关问题

2012-01-26 
用VC中的文件操作实现读取文本数据问题求助:我现在不用C或者C++,而只用VC中的文件操作实现读取文本数据,但

用VC中的文件操作实现读取文本数据问题
求助:我现在不用C或者C++,而只用VC中的文件操作实现读取文本数据,但是读出来却都是零,请教高手该怎么实现!
文本文件的格式如下:
----------------------------------------------
    x                           y                       z                     t
41.6318             82.6541             13.9728             10                    
47.1548             84.4877             17.1848             10.1                    
46.2162             88.5444             15.5791             10.3                  
47.1084             91.0505             18.3721             11                  
52.3068             96.8492             21.4649             12.1      
53.9832             100.539             22.9719             12.8  
------------------------------------------------------            
我要做的就是将里面的数据一行一行的读出来,然后将每行的数据赋给x,y,z,t,然后对这些数据进行运算,我用VC的实现代码如下:
char   buff[200];
CString   str,str1,str2,str3;
float   x=0,y=0,z=0,t=0;

CStdioFile   *pFile=new   CStdioFile();
pFile-> ReadString(buff,200);
while(pFile-> ReadString(str))
{
    str1=str.Left(str.Find( " "));
    x=atoi(str1);
}
但是查看x却等于0,不知是哪里有错!请高手给出一个解决方案

[解决办法]
把str1=str.Left(str.Find( " "));改为str1=str.Left(str.Find( ' '));//寻找空格,不是空串
[解决办法]
试了一下,用以下代码能输出每行的x
//char buff[200];
CString str,str1,str2,str3;
float x=0,y=0,z=0,t=0;

CStdioFile *pFile=new CStdioFile();
pFile-> Open( "1.txt ", CFile::modeRead);
//pFile-> ReadString(buff,199);
while(pFile-> ReadString(str))
{
str1=str.Left(str.Find( ' '));
x=atof(str1);
MessageBox(str1);
}
pFile-> Close();
//MessageBox(str1);

热点排行