简体   繁体   中英

c++: Writing to a file

I have a couple of questions.

First, i am doing http byte range requests and then writing the received data to a file. Sometimes, i have to read a block of 1K, and then read that from the file fetched through http. Now, the problem is that the next request after the 1k request may be starting from 100 bytes and in that case i want to write in the 1K file, overwriting from 100 bytes. How can i overwrite from a specific offset in the file?

Secondly, how do i create a file with some data already in the file? For eg. i want put the data in the file from lets say 500th byte, i do not care about the first 500 bytes, could be any garbage data, but its important to have the correct file size for the code to work.

thanks

http://www.cplusplus.com/reference/iostream/ostream/seekp/上有一些关于seekpseekp参考资料和示例代码

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM