Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!uakari.primate.wisc.edu!uflorida!bikini!thoth From: thoth@springs.cis.ufl.edu (Robert Forsman) Newsgroups: comp.lang.c++ Subject: Re: Formatted Output Revisited Message-ID: Date: 21 Oct 89 01:25:23 GMT Sender: news@uflorida.cis.ufl.EDU Distribution: comp Organization: /cis/lightning0/thoth/.organization Lines: 43 I agree, form looks evil and brings up the specter of printf. > From: inst182@tuvie (Inst.f.Techn.Informatik) > One possible solution is to introduce a new operator that handles > formatting. . . . Two unused ASCII characters remain: > `@' and `#'. So what about > cout <<4#2<<5.2#6#4; > or > cout <<4@2<<5.2@6@4; > From: carroll@paul.rutgers.edu (V. I. Lenin) > 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; I assume you guys have already discussed the idea of an explicit conversion and trashed it. String decimalString(int value,int width); String hexString(int value,int width); String decimalString(float value,int width,int decimals=-1); (and for those manic math lovers like me :^) String anybaseString(float value,unsigned int base, int width,int decimals=-1); cout << decimalString(4,0); cout << "Time to impact :" << decimalString(boom,1,2) << '\n'; Needless to say you could provide a simple subset for users with much shorter names and let them write their own anybaseString(). ( side note. I had trouble with that '\n' being converted to an int before reaching the ostream. I decided to typecast it and that solved the problem. It was probably just a compiler "bug") -- (U. of F., the only place where the CIS department has its own beach :)