I would image that 'cout.setf(ios::unitbuf)' would make cout be unbuffered (see http://www.cppreference.com/io_flags.html ).
However, a better solution might be to use cerr instead of cout for progress information. cerr is unbuffered by default (so you can be sure your error messages get written before your program crashes). Plus, if you aren't interested in the progress info for a given run, you can just do: ./a.out 2>/dev/null and progress won't be written to the terminal -- Bradford Powell On Thu, 22 Sep 2005, Wing D Lizard wrote: > fflush(stdout) is 'not recommended' > > look here. > > http://www.cplusplus.com/ref/iostream/istream/sync.html > > > Randall Patrick Barlow wrote: > > > I wrote a console based program under Windows, and I then compiled the > > same code with g++ under Linux. The program is supposed to output to > > the screen the percentage done periodically, so the user has some idea > > if the program will take minutes, hours, days, etc. In Windows, this > > works great. However, in Linux, it doesn't seem to get written to the > > screen every time I cout, as if there were some kind of buffer that > > were filling up and waiting to get to a certain level before dumping > > to the screen (under bash). The line of code that writes to the > > screen is something like: > > > > cout << '\r' << [code to determine percentage done] << "% complete"; > > > > Any ideas why I don't see this all the time? It does eventually come > > out, but nothing until it's written several times. I even have an > > initial line that is supposed to write 0% done, and that never shows > > up (but does in Windows). It's no big deal, but it does bug me :) > > > > Thanks, > > Randy > > > > > -- > No virus found in this outgoing message. > Checked by AVG Anti-Virus. > Version: 7.0.344 / Virus Database: 267.11.4/109 - Release Date: 9/21/2005 > > -- > TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug > TriLUG Organizational FAQ : http://trilug.org/faq/ > TriLUG Member Services FAQ : http://members.trilug.org/services_faq/ > TriLUG PGP Keyring : http://trilug.org/~chrish/trilug.asc > -- TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug TriLUG Organizational FAQ : http://trilug.org/faq/ TriLUG Member Services FAQ : http://members.trilug.org/services_faq/ TriLUG PGP Keyring : http://trilug.org/~chrish/trilug.asc
