Fstream binary read and write.

Hello I'm currently working on a program that uses this type of code
fstream fbin(textfilename, ios::binary|ios::out|ios::in)
The program later goes on to a switch statement allowing the user to read or write depending on a choice.
The problem I am having is that when creating the fbin object it's as though I need the file to be already created since im using the flag ios::in
is there a possible way to allow fbin.write(text, number) to work without a pre-existing file.
Thanks

also I don't want more than one object for this.
closed account (zb0S216C)
snig wrote:
"The problem I am having is that when creating the fbin object it's as though I need the file to be already created since im using the flag ios::in"

Only output streams create a file if the file is non-existent.

snig wrote:
"is there a possible way to allow fbin.write(text, number) to work without a pre-existing file."

No. The file must be existent when you open it.

Wazzak
Topic archived. No new replies allowed.