lexcast.cpp 514 B

123456789101112131415161718
  1. // lexcast.cpp -- simple cast from float to string
  2. #include <iostream>
  3. #include <string>
  4. #include "boost/lexical_cast.hpp"
  5. int main()
  6. {
  7. using namespace std;
  8. cout << "Enter your weight: ";
  9. float weight;
  10. cin >> weight;
  11. string gain = "A 10% increase raises ";
  12. string wt = boost::lexical_cast<string>(weight);
  13. gain = gain + wt + " to "; // string operator+()
  14. weight = 1.1 * weight;
  15. gain = gain + boost::lexical_cast<string>(weight) + ".";
  16. cout << gain << endl;
  17. return 0;
  18. }