Thomas Eding
Thomas Eding

Reputation: 1

C++ read and write to same file using different streams

I have two streams pointing to the same file. The first one is std::ofstream os and the second is std::ifstream is, both opened in binary mode.

I'm using os to create a new file. The file creation process requires me to (at times) read data that was written to the file by os. The is stream seeks to the needed position, reads some data, and then os does it's thing at its (distinct) offset and then flushes.

Is this legal to do? Will the streams stomp on each other?

Upvotes: 2

Views: 338

Answers (1)

deviantfan
deviantfan

Reputation: 11414

Can´t quote any standard, but/because this is platform specific
(maybe exclusive access, buffering on different levels...)

You could just use a single fstream with ios::in|ios::out
and seek before every action.

Upvotes: 0

Related Questions