0

I want to create file if it doesn't exist, or append to the end if it does, but also be able to read:

 std::fstream::binary | std::fstream::in | std::fstream::out | std::fstream::ate

The current answers 1 2 all suggest I can either get rid of the ability to read the file, or truncate it. Google provides one post that scolds the asker for not finding another post which is long gone along with its author and "hints" it's a two-step process...

Community
  • 1
  • 1
SF.
  • 13,549
  • 14
  • 71
  • 107
  • isn't the second answer [here](http://stackoverflow.com/questions/8835888/stdfstream-doesnt-create-file) not an option for you? – Biruk Abebe May 12 '16 at 12:39
  • @bkVnet: Answers have no inherent ordering. The ordering you see may be different for someone else, and will change over time. Best to identify answers by direct URL or by author's name. – Lightness Races in Orbit May 12 '16 at 12:45
  • Congratulations on 5,555 rep :D – Lightness Races in Orbit May 12 '16 at 12:46
  • @bkVnet: Won't that truncate the file if exists but its current permissions are 'write only'? (e.g. UNIX chmod 222) – SF. May 12 '16 at 12:50
  • @LightnessRacesinOrbit: Thanks. I edited the tags of the linked question - lack of 'fstream' was what probably made me miss it. As for 5555, I was above that last week, then I found an answer for a question about something *extremely* annoying me, and mere +10 karma for its author wouldn't cut it :) – SF. May 12 '16 at 12:58
  • @SF Yes it does. but according to the documentation for [std::basic_filebuf::open](http://en.cppreference.com/w/cpp/io/basic_filebuf/open) you can uses `std::fstream::binary | std::fstream::in | std::fstream::out | std::fstream::app` since this combination will create a file if it doesn't exit. – Biruk Abebe May 12 '16 at 13:09
  • @SF. [tag:fstream] is a pretty terrible tag. – Lightness Races in Orbit May 12 '16 at 13:14
  • @LightnessRacesinOrbit: iostream is only about standard input/output. I wouldn't think about looking for file operations under it. – SF. May 12 '16 at 21:07
  • @SF No, file streams are part of the I/O Streams library. – Lightness Races in Orbit May 12 '16 at 21:10

0 Answers0