2

I want to open a file for read and write with std::filebuf, but create the file if it doesn't exist yet. If it already exists, do nothing. I want to freely write into the file, without any "always jump to end before each write" behavior. What open mode should be used?

According to the table , there appears to be no combination of flags to do that.

What's the best option to ensure this effect?

Yunus Temurlenk
  • 4,085
  • 4
  • 18
  • 39
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
  • 1
    Is it a requirement to open the file only once? If not, this sequence may serve: Open for append, close, open for read+write? – Ben Voigt Mar 17 '20 at 14:19
  • @BenVoigt thanks, that would work. You may answer. But I find it surprising that such a simple task requires that workaround. It would appear to me that's the most frequent usecase I'm facing. – Johannes Schaub - litb Mar 17 '20 at 14:23

0 Answers0