Using Boost

Although you now can access many Boost-developed libraries as part of the C++11 standard, there are many additional Boost libraries to explore. For example, lexical_cast from the Conversion library provides simple conversions between numeric and string types. The syntax is modeled after dynamic_cast, in which you provide the target type as a template parameter. Listing 18.11 shows a simple example.

Listing 18.11. lexcast.cpp

// lexcast.cpp -- simple cast from float to string#include <iostream>#include <string>#include "boost/lexical_cast.hpp"int main(){    using namespace std;    cout << "Enter your weight: ";    float weight;    cin >> weight;    string gain = "A 10% increase raises ";    string wt = boost::lexical_cast<string>(weight); ...

Get C++ Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.