PracticeDev/study_cpp/cpp_primer_source_code/Chapter 18/lexcast.cpp

19 lines
532 B
C++
Raw Permalink Normal View History

2022-12-20 17:31:11 +08:00
// 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);
gain = gain + wt + " to "; // string operator+()
weight = 1.1 * weight;
gain = gain + boost::lexical_cast<string>(weight) + ".";
cout << gain << endl;
return 0;
}