This statement here doesn’t seem to be correct:
Bidirectional file streams, on the other hand, do not have the flag
set implicitly. This is because a bidirectional stream
does not have to be in both input and output mode in all cases. You
might want to open a bidirectional stream for reading only or writing
only. Bidirectional file streams therefore have no implicit input or
output mode. You must always set a bidirectional file stream’s open
mode explicitly.
otherwise, this code wouldn’t compile.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream file("novo.txt", ios::out);
char i;
file >> i;
}
Although there has historically been some confusion regarding this matter, I believe the statement you quoted is indeed misleading, but not for the reason in your example. Bidirectional file streams do set the flag implicitly, as noted in the documentation:
Based on the Apache statement, I would NOT expect your code sample to fail, as it explicitly sets the flag to ::out. I would, on the other hand, expect this code to fail:
But based on the MSDN documentation, this code will not fail either, and the file will default to ios_base::in & out (and, hence, the Apache statement is not entirely accurate).