From 538fa3bd36977e995dc0d994d072fed5e6af2478 Mon Sep 17 00:00:00 2001 From: fmckenna Date: Fri, 2 Aug 2024 08:48:11 -0700 Subject: [PATCH] fmk - adding outputFormatted --- code/c++/outputFormatted.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 code/c++/outputFormatted.cpp diff --git a/code/c++/outputFormatted.cpp b/code/c++/outputFormatted.cpp new file mode 100644 index 0000000..58b21b7 --- /dev/null +++ b/code/c++/outputFormatted.cpp @@ -0,0 +1,21 @@ + +// formatted outut looks awful before c++20 + +#include +#include +#include + +int main() { + double d = 50.0123456789; + + std::string s; + std::stringstream sstream; + sstream.setf(std::ios::fixed); + sstream.precision(10); + sstream << d; + + s = sstream.str(); + std::cout << d << std::endl; + std::cout << s << std::endl; + return 0; +}