I don't know if this was what you tried, but you have to do:
file << "Hello World" << std::flush;
Update; I am leaving this answer here due to helpful comments
Based on the feedback, I will change my advice: you do not need to explicitly call std::flush (or file.close() , for that matter), because the destructor does this for you.
In addition, a call to flush explicitly forces an I / O operation, which may not be the most optimal. It will be better to correspond with the basic iostreams and the operating system.
Obviously, the OP problem is not related to calling or not calling std::flush , and probably due to trying to read the file before the file stream destructor was called.
John weldon
source share