I'm using the Boost Tee_device class to output Text to both cout and a ofstream. Using this example. Only difference is that my typedef for TeeDevice looks like this.
typedef io::tee_device<ostream, ofstream> TeeDevice;
typedef io::stream< TeeDevice > TeeStream;
That part works great.
My problem comes when trying to write a progress bar using the stream object. I'm using '\r'
to send the courser back to the beginning of the line.
Here's what the code I'm using looks like,
//Some code that inits TeeStream* Tee_streamObj;
(*Tee_streamObj) << "Progress:"<< "\n" <<std::flush();
for(int x = 0; x <= 100; x++)
{
(*Tee_streamObj) << '\r' << (x*100)/100<<"%"<<std::flush();
}
(*Tee_streamObj) << '\r' << "Complete!"<<std::flush();
In cout I get 2 lines, the second line keeps getting overwritten and finally looking just like this.
Progress:
Complete! //<-- line keeps getting overwritten as desired
but the file generated from the ofstream looks like this,
Progress:
0%
1%
2%...
99%
100%
Complete!
Is there a way to overwrite the last line written to an ofstream in boosts Tee_device class?
I'm using version 1.40 of the boost library and should note that I don't have any control over using a different version.
Ideas?
Thanks ahead of time.
Edit: I've been playing around with making the ofstream into a fstream. Is there a way to accomplish something like this using seekg or tellg?