Reputation: 51255
What happens when I try to open a file using std::ifstream
while that file is being written to by another application?
Upvotes: 2
Views: 1397
Reputation: 163277
That depends on the sharing mode used to open the file in the other program. If the open mode you use is compatible with the sharing mode, then you'll open the file. Otherwise, the open will fail. C++ doesn't really offer "sharing modes," though, so the sharing modes you get will be whatever your vendor's implementation happens to use. If you really want control over how you open a file, use the OS-provided functions (CreateFile
, in this case).
As writes from the other program take effect, you'll be able to read them in your program. If you also write to the file, then your writes and the other program's writes might interfere with each other, causing data loss or jumbled output; don't do that.
Upvotes: 3