lisch@lisch.mentor.com (Ray Lischner) (05/24/90)
> > Formatting with cout seems pretty painful. Is it possible to > > use *printf() instead of cout and still maintain the program > > portability? And is it possible mix up both cout and *printf()? > > > > S. Manoharan Janet: sam@uk.ac.ed.lfcs > ---------- > > Mixing cout and printf can be dangerous due (I believe) to different > buffering schemes. The order of things printed may surprise you. > I have even seen printf output completely lost when I mixed couts > and printfs. I have found that I can avoid problems, however, by > alway flushing printf output before using cout and vice versa. From the AT&T C++ Language System Library Manual, Appendix A, Iostream Library Manual Pages, page 7 of IOS(3C++): ios::sync_with_stdio() Solves problems that arise when mixing stdio and iostreams. The first time it is called it will reset the standard iostreams (cin, cout, cerr, clog) to be streams using stdiobufs. After that input and output using these streams may be mixed with input and output using the corresponding FILEs (stdin, stdout, stderr) and will be properly synchronized. sync_with_stdio() makes cout and cerr unit buffered (see ios::unitbuf and ios::stdio above). Invoking sync_with_stdio() degrades performance a variable amount, depending on the length of the strings being inserted (shorter strings incur a larger performance hit). -- Ray Lischner UUCP: {uunet,apollo,decwrl}!mntgfx!lisch -- Ray Lischner UUCP: {uunet,apollo,decwrl}!mntgfx!lisch