|
Boost Users : |
From: Navneet Dalal (Navneet.Dalal_at_[hidden])
Date: 2004-04-14 14:11:38
Hi
I decided to try boost::format for more compact and typesafe formatting of
text. However, I am running into some problems.
Problem 1
==============
The following line throws boost:bad_format_string exception.
std::cout << format("%|1| %|2$3|") % "Hello" % 3 << std::endl;
However, this one works
std::cout << format("%|1|") % "Hello" << std::endl;
All I want to do is use notation for printing character streams i.e. %|1|
instead of %1%
Is this a bug or I am doing something wrong?
Problem 2
=============
How can I print a float such that it appends 0 for remaining precision digits.
For e.g. let us say I want to print 0.2 with 5 characters of overall length
and till 3 digits of precision. Kind of output I am looking for is 0.200
One would expect that following command may work (as I am indicating left
print, fill any remaining characters and till 3 digits of precision after
decimal)
std::cout << format("#%|1$-05.03|#") % 0.2 << std::endl;
// however it prints
#0.2 #
This command prints something like
std::cout << format("#%|1$05.03|#") % 0.2 << std::endl;
// it prints
#000.2#
with C++ cout, I can print it like
std::cout << '#' << std::left << std::setfill('0') << std::setw(5) <<
std::setprecision(3) << 0.2 << '#' << std::endl;
so on similar lines I wrote following line. it works, but it seems ugly to use
group only for this
std::cout << format("#%|1$-05.3|#") % group(setfill('0'), 0.2) << std::endl;
// prints
#0.200#
Does any one has any other suggestions?
regards
navneet
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net