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); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access