For the record, Jerome replied off-list repeating the incorrect claim that this doesn't work, and when I repeated that he misunderstands the API, he replied *again* claiming that you can't read from an ifstream opened with ios::out. Because he didn't bother to read what I wrote (twice) nor bother to read the standard reference I provided.

I've now provided a working example to prove that his claim is wrong:
https://godbolt.org/z/zjd4oYh3h

I'll see where that goes, but I'm starting to wonder if he is just trolling this list.



On Sat, 6 Sept 2025, 22:23 Jonathan Wakely, <cxx@kayari.org> wrote:


On Sat, 6 Sept 2025 at 12:06, Jerome Saint-Martin via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
Problem
The current ifstream/ofstream API allows illogical mode combinations:
  std::ifstream f("data.txt", std::ios::out); // Compiles, but doesn't work
What doesn't work here?

The filebuf is opened with mode ios::out|ios::in and so reading from the ifstream works fine.

See https://eel.is/c++draft/ifstream.cons#2.sentence-1