You can achieve a kind of automatic synchronization for output files by using the format flag ios_base::unitbuf. It causes an output stream to flush its buffer after each output operation as follows:
std::ofstream ostr("/tmp/fil");
std::ifstream istr("/tmp/fil");
ostr << std::ios_base::unitbuf; //1
while (some_condition) {
ostr << "... some output ..."; //2
// process the output
istr >> s;
// ...
}
Since it is not overly efficient to flush after every single token that is inserted, you might consider switching off the unitbuf flag for a lengthy output that is not supposed to be read partially.
ostr.unsetf(std::ios_base::unitbuf); //1 ostr << "... some lengthy and complicated output ..."; ostr.flush().setf(std::ios_base::unitbuf); //2