Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
Field Width, Fill Character and Adjustment

boost::cnv::strtol cnv;

string s01 = convert<string>( 12, cnv(arg::width = 4)).value();
string s02 = convert<string>( 12, cnv(arg::width = 5)
                                     (arg::fill = '*')).value();
string s03 = convert<string>( 12, cnv(arg::width = 5)
                                     (arg::fill = 'x')
                                     (arg::adjust = cnv::adjust::left)).value();
string s04 = convert<string>(-98, cnv(arg::width = 6)
                                     (arg::fill = 'Z')
                                     (arg::adjust = cnv::adjust::right)).value();

string s05 = convert<string>(-12.3451, cnv(arg::precision = 2)
                                          (arg::width = 10)
                                          (arg::fill = '*')
                                          (arg::adjust = cnv::adjust::left)).value();
string s06 = convert<string>(-12.3450, cnv(arg::adjust = cnv::adjust::right)).value();
string s07 = convert<string>(-12.3450, cnv(arg::adjust = cnv::adjust::center)).value();

BOOST_TEST(s01 == "  12");
BOOST_TEST(s02 == "***12");
BOOST_TEST(s03 == "12xxx");
BOOST_TEST(s04 == "ZZZ-98");
BOOST_TEST(s05 == "-12.35****");
BOOST_TEST(s06 == "****-12.35");
BOOST_TEST(s07 == "**-12.35**");


PrevUpHomeNext