本文介绍了在第140个位置和176个位置读取长4个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是havinig文件. 文件大小1200 我正在通过ifstream读取文件.
Hi i am havinig file. file size 1200 i am reading the file thru ifstream.
outHdrFile.seekg(0, ios::end); long Hdrlen = outHdrFile.tellg(); ifstream::pos_type HdrPtr; HdrPtr = Hdrlen;// - headerSize; BYTE* HdrFileBuff = new BYTE[HdrBufferSize]; outHdrFile.seekg (140, ios::beg); outHdrFile.read((char*)HdrFileBuff,HdrPtr);从第140个位置读取4个字节,并将其写入具有第140个位置的临时文件中.在第140个位置6中,我必须在那里更新6100. 请告诉我如何以最少的行数进行更新. 谢谢
reading 4 bytes from 140th postion and write that into a temp file with same position 140th .in 140th position 6 is there and i have to update 6100 there. pls tell me how to update in minimum lines. thanks
推荐答案忘记进行这种类型的交易时要寻求的知识;这样做:
- 读取输入文件的后N个字节(在这种情况下为140).
- 将这些字节写入输出文件.
- 读取后N个字节(4个). /li>
- 修改刚刚读取的值.
- 将修改后的值写入输出文件.
- 重复此操作,直到复制所有数据. Forget about seeking when doing this type of transction; do it this way:
- Read the next N bytes of input file (in this case 140).
- Write those bytes to the output file.
- Read the next N bytes (4).
- Modify the value just read.
- Write the modified value to the output file.
- Repeat until all data is copied.
更多推荐
在第140个位置和176个位置读取长4个字节
发布评论