fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. double a = 157.2734;
  10. cout << "This number is " << fixed << setprecision(1) << a << "." << endl;
  11. ostringstream fmtStr;
  12. fmtStr << "This number is " << fixed << setprecision(1) << a << ".\n";
  13. string line = fmtStr.str();
  14. cout << line;
  15. return 0;
  16. }
Success #stdin #stdout 0s 4520KB
stdin
Standard input is empty
stdout
This number is 157.3.
This number is 157.3.