Boost C++ Libraries 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.


Boost.Convert builds on the boost::lexical_cast experience and takes those type conversion/transformation-related ideas further

Boost.Convert provides new and familiar conversion/transformation-related functionality such as:

Boost.Convert consists of two components:

The boost::convert() user interface

The collection of pluggable converters is independent of the boost::convert() API facade and is designed to be extendible and extended over time. Currently the following converters are provided:

The converters provide new and familiar functionality and demonstrate how existing and independent conversion facilities might be incorporated in to the Boost.Convert framework. For example, the std::stream-based converter draws on the standard std::streams functionality and provides:

The following code demonstrates conversion of an array of integers from their textual hexadecimal representation and assigns -1 to those which fail to convert:

boost::array<char const*, 3> strs = {{ " 5", "0XF", "not an int" }};
std::vector<int>             ints;
boost::cnv::cstream           cnv;

// Configure converter to read as a string of hexadecimal characters, skip (leading) white spaces.

std::transform(strs.begin(), strs.end(), std::back_inserter(ints),

BOOST_TEST(ints.size() == 3); // Number of values processed.
BOOST_TEST(ints[0] ==  5);    // " 5"
BOOST_TEST(ints[1] == 15);    // "0XF"
BOOST_TEST(ints[2] == -1);    // "not an int"