Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > C/C++ > vc 中CFile 类的seek 随机读取问题 --血的教训
【标  题】:vc 中CFile 类的seek 随机读取问题 --血的教训
【关键字】:vc,CFile,seek
【来  源】:http://www.cublog.cn/u/20725/showart.php?id=215697

vc 中CFile 类的seek 随机读取问题 --血的教训

Your Ad Here
写了如下的一段vc代码,本来是准备使用Seek在文件中随机定位,然后读出相应位置上的float数据的,测试的时候,却发现和想象的结果相差很远。
CFile file;
 float *m_Data=new float[tmpRow];
 file.Open(filename, CFile::modeRead);
 for(int j=0;j<tmpRow;j++)   
 {
      file.Seek(j, CFile::begin );   
      file.Read(tmpval, sizeof(float));
      m_Data[j]=*tmpval;
 }
 
苦苦思考了一下午。 仔细阅读了MSDN中的说明,方才搞清楚原来应该使用
file.Seek(j*sizeof(float), CFile::begin );   
Seek( LONG lOff, UINT nFrom )中的lOff是以byte为单位的,而不是自动根据数据格式调整。
把MSDN中的一段附在后面,立此存照。
唉,教训啊,开始的时候没有仔细看清楚。
 

CFile::Seek

virtual LONG Seek( LONG lOff, UINT nFrom );
throw( CFileException );

Return Value

If the requested position is legal, Seek returns the new byte offset from the beginning of the file. Otherwise, the return value is undefined and a CFileException object is thrown.

Parameters

lOff

Number of bytes to move the pointer.

nFrom

Pointer movement mode.  Must be one of the following values:

  • CFile::begin   Move the file pointer lOff bytes forward from the beginning of the file.

  • CFile::current   Move the file pointer lOff bytes from the current position in the file.

  • CFile::end   Move the file pointer lOff bytes from the end of the file. Note that lOff must be negative to seek into the existing file; positive values will seek past the end of the file.
61条面向对象设计的经验原则(转):【上一篇】
iterator(一):【下一篇】
【相关文章】
  • vc++ memcpy和 memmove, 在source和destination有重叠时出现的问题
  • 一个速度不错的PSP电影批量转AVC的软件
  • 制作高清晰全屏影视PMPAVC的方法
  • php.mvc
  • VC的IDE在编译链接时做了些什么--- 逆向工程写自己的vcspawn
  • 唉……原来是VC++8的STL有内存泄漏……
  • 揭秘流氓软件盛行内幕 VC实为幕后推动者
  • Register fails when upgrade ATL project from VC7.1/VS2003 to VC8/VS2005
  • VC++动态链接库编程之非MFC DLL
  • 多线程VC++和Matlab混编在信号采集和处理中的应用
  • 【随机文章】
  • sprint ipmon project page
  • meeting log with Rongguang, Mr. Fu, and Jason
  • 简单实现Windows和Linux文件共享(samba)
  • FreeBSD连载(44):X Free86的硬件要求
  • Windows 2000 网络环境部署
  • SEH 於病毒的應用
  • asp生成excel数据报表
  • 一个很准的心理测试
  • 治愈红血丝还需美国圣美安
  • 网管第一部 —— 网管软件的应用
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.