rank1
rank1

Reputation: 1038

how to open fstream for both reading and writing operation in Visual Studio

For my project I want to use Fstream to open file and I want to open it for both reading and writing operations at once. I am using Visual Studio.
Normally it would be just file.open(); but since there is a bug in Visual Studio (You can find more on it in this topic How do I operate on file using fstream pointers? in comments to sftrabbit answer) it is not that easy. File.Open() will open the file only for reading (writing will make no effect) and to open in that way file for writing we need to do file.open(path, std::fstream::in | std::fstream::out | std::fstream::trunc) but this will open it only for writing, not for reading.

Any ideas how to open the file with just one line ?

Upvotes: 2

Views: 4615

Answers (1)

IcyFlame
IcyFlame

Reputation: 5199

Simple code.

stream file;
file.open(fileName,ios::in | ios::out);

The symbol to be used between flags is the piping symbol.

Upvotes: 3

Related Questions