Click here to Skip to main content
16,019,182 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am havinig file.
file size 1200

i am reading the file thru ifstream.

C#
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);


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
Posted

1 solution

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.
 
Share this answer
 
Comments
JOYKAIGA1 18-Aug-12 9:15am    
how to print in ascii of that long data type?
Richard MacCutchan 18-Aug-12 11:09am    
Any way you like, it all depends what it represents. You could print it as 4 bytes, 2 half words or 1 whole word. You can use printf() or one of its variants with the X format specifier, or cout with the hex manipulator.
Sergey Alexandrovich Kryukov 18-Aug-12 17:59pm    
Makes full sense, a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900