fork download
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <sstream>
  4.  
  5. int main(int argc, char **argv)
  6. {
  7. std::stringstream ss;
  8. double x = -1.890123;
  9.  
  10. //insert x into the stream twice with different precisions each time
  11. ss << std::setprecision(2) << x << std::endl
  12. << std::setprecision(8) << x << std::endl;
  13.  
  14. //insert the std::string representation of ss into std::cout
  15. std::cout << ss.str();
  16.  
  17. return 0;
  18. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
-1.9
-1.890123