Reputation:
I write my output results which are emitted by Solver()
function (a function in caffe
third library), in a file with these command:
if(std::freopen("redir.txt", "w", stdout)) {
std::printf("stdout is redirected to a file\n"); // this is written to redir.txt
solver->Solve();
std::fclose(stdout);
}
but since the Solve()
function emits outputs continuously, but the redir.txt
will not be updated until the std::fclose(stdout);
is executed. So I can't see the results real time.
How can I update my file in real time?
Upvotes: 0
Views: 541
Reputation: 31467
Use std::flush at regular intervals to flush the written (buffered) data to the file.
Don't flush
too often though or performance will be impacted.
Upvotes: 5