Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2049809
  • 博文数量: 454
  • 博客积分: 10921
  • 博客等级: 上将
  • 技术积分: 5396
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-15 15:20
个人简介

伪IT男

文章分类

全部博文(454)

文章存档

2016年(2)

2013年(6)

2012年(17)

2011年(29)

2010年(24)

2009年(54)

2008年(53)

2007年(202)

2006年(67)

分类: C/C++

2006-12-14 20:13:59

写了如下的一段vc代码,本来是准备使用Seek在文件中随机定位,然后读出相应位置上的float数据的,测试的时候,却发现和想象的结果相差很远。
CFile file;
 float *m_Data=new float[tmpRow];
 file.Open(filename, CFile::modeRead);
 for(int j=0;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.
阅读(5134) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~