Click here to Skip to main content
15,886,746 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi Guys,

I am reading a file using fstream,
and storing the contents in a char buffer.
its size is 1200 bytes.
i want to write that buffer into a temp file by deleting contents and appending some bytes to the temp file.
example below

C++
for(i=0;i<buffesize;i++)>
{
if i>200 && i<205) continue; 
// here it skips the 4bytes.i want to append in same position which existing should
// not print
tempfile<<buffer[i];
}


before writing into a file i want to delete 4bytes in a 200th position and append 8 bytes in the same poistion.

can anyone help in this regard


thanks
Posted
Updated 14-Aug-12 21:21pm
v2
Comments
ChineseGuy 16-Aug-12 6:17am    
move the data from 204th 4 steps to right.
and write your 8 bytes from 200th

You can do this without manipulating the buffer yourself.
Just use seekg to set the readpointer to the right position.
And seekw to set the writepointer to the right position.
Of course you also need to take the filesize into account, you cannot seek beyond the end of the file.

see also this link:
http://www.cplusplus.com/reference/iostream/fstream/[^]
 
Share this answer
 
Comments
JOYKAIGA1 15-Aug-12 3:28am    
can you tell me the same how to do using fseek() etc?as i am using only iostream and ifstream?
Once you have your data in the buffer you can write out a number of characters at a time with the write() function, as described here[^]. You just need to write the first block from the buffer, then the 8 new characters, and lastly the second block from the buffer.
 
Share this answer
 

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