yep, but do
printf("% 02.2f")
with cout and maybe add a few more numbers with different formatting. yes, cout can do it.. in a line thats about half a mile long and definitely beat in terms of simplicity (not in terms of readability of course ,-) ). guess you can tell i prefer printf in 99% of all cases, because all the "text" << number << "more test" << another number << endl is driving me crazy ,-)
edit: at the same time, having a dozen variables in one printf might make you loose track of which belongs where.
[edited by - Trienco on February 21, 2004 2:25:02 AM]
How would you convert this to C++ from C?
quote:Original post by CGameProgrammer
And I still don''t see how it can give you all the formatting printf can (decimal places, mainly).
You can use setw and setprecision for that.
A lot of smart people thought about the iostreams library for at LEAST a good couple of hours before they went ahead and coded it. The chances that they''d miss something like that are not good.
"Sneftel is correct, if rather vulgar." --Flarelocke
quote:Original post by CGameProgrammerAhem. In the future, RTFM. Especially before making pronouncements about what can or can''t be done.
I don''t get it. Are dec/oct/hex constants that are defined somewhere, like endl, that indicate the following value should be in that format? And I still don''t see how it can give you all the formatting printf can (decimal places, mainly). I''m sure it can be done, but probably only by using std::string''s functions.
quote:Original post by TriencoIf you absolutely must, boost::format.
...maybe add a few more numbers with different formatting. yes, cout can do it.. in a line thats about half a mile long and definitely beat in terms of simplicity...
One last thing. With printf''s format specifiers, the onus is on you to match the specifier to the variable you''re actually passing. If you get it wrong, it''s not a compiler error, so you will simply see aberrant behavior at runtime. With cout & co, an insertion operator is overloaded for each type making it typesafe. Furthermore, inserting an unexpected type (one for which no insertion operator exists) will generate a compiler error, and inserting the wrong value will generate results consistent with that formatting (several digits of precision if a float is substituted for an int; a letter if a char is substituted for a float, etc).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement