O'Reilly logo

C++ Primer Plus by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required