Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!brutus.cs.uiuc.edu!psuvax1!rutgers!aramis.rutgers.edu!paul.rutgers.edu!carroll From: carroll@paul.rutgers.edu (V. I. Lenin) Newsgroups: comp.lang.c++ Subject: Re: Formatted Output Revisited Message-ID: Date: 16 Oct 89 15:48:16 GMT References: <738@tuvie> Organization: Rutgers Univ., New Brunswick, N.J. Lines: 48 > It's high time the problem of formatted output be addressed. Not only has it been addressed, but it has been solved in 2.0's iostream library. > The current method of providing formatted output ( the form() > function form() is not the current method. 2.0 doesn't even have it, for precisely the reasons you state. As I've discussed before on this group, the perfectly elegant solution in 2.0 is to use ostrstreams. Ostrstreams have all the properties you desire: > + Typechecking is possible at compile-time. True for ostrstreams. > + This concept can be used with user-defined types as well. True for ostrstreams. Just define a new ostream insertion operator, and you can use that operator to insert into any kind of stream you like: cout, core buffers, whatever. > + The use of a format operator logically extends the idea of > using input/output operators. In 2.0 iostreams, format "operators" are called manipulators. They get inserted (more correctly, the illusion is that they get inserted) into streams just like real data, e.g.: cout << hex << 12 << dec << 12 << endl; outputs "c12". > + Optimization is possible:... Insertion operators and manipulators can be inlined like anything else. > + It doesn't involve writing a lot of extra chars. (That's > important!!! :-) You don't gotta write *anything* extra with 2.0 iostreams. Just define the new insertion operator, and everybody who needs it inherits it automatically. -- martin