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 for the latest Boost documentation.
PrevUpHomeNext

Formatting Support

Numeric Base (bin, oct, dec, hex)
Field Width, Fill Character and Adjustment
Leading Whitespace Characters
Floating-Point Precision

#include <boost/convert.hpp>
#include <boost/convert/strtol.hpp>

using std::string;
using std::wstring;
using boost::convert;

namespace cnv = boost::cnv;
namespace arg = boost::cnv::parameter;

boost::cnv::strtol cnv;

BOOST_TEST( "11111110" == convert< string>(254, cnv(arg::base = cnv::base::bin)).value());
BOOST_TEST(      "254" == convert< string>(254, cnv(arg::base = cnv::base::dec)).value());
BOOST_TEST(       "FE" == convert< string>(254, cnv(arg::base = cnv::base::hex)).value());
BOOST_TEST(      "376" == convert< string>(254, cnv(arg::base = cnv::base::oct)).value());

BOOST_TEST(L"11111110" == convert<wstring>(254, cnv(arg::base = cnv::base::bin)).value());
BOOST_TEST(     L"254" == convert<wstring>(254, cnv(arg::base = cnv::base::dec)).value());
BOOST_TEST(      L"FE" == convert<wstring>(254, cnv(arg::base = cnv::base::hex)).value());
BOOST_TEST(     L"376" == convert<wstring>(254, cnv(arg::base = cnv::base::oct)).value());


PrevUpHomeNext