I try to test the following situation: a file is opened for write, then the file is removed and then something is written to the opened. Here is the source code:
std::ofstream stream("a.txt");
std::string a("before");
stream.write(a.c_str(), a.size());
stream.flush();
std::filesystem::remove("a.txt");
std::cout << stream.good() << std::endl;
std::string b("after");
stream.write(b.c_str(), b.size());
stream.flush();
std::cout << stream.good() << std::endl;
The program works in the expected way: the file does not exist after the execution. Nevertheless, none of fail flags is set and the stream is considered as a good one. Why?
P.S. OS: Ubuntu 20.04, Compiler g++ 9