From 949818cd8b4a1c9e979ba0b2d6572d9958b198b5 Mon Sep 17 00:00:00 2001 From: David Wells Date: Thu, 16 Mar 2017 18:22:16 -0400 Subject: [PATCH] Restore std::cout flags. --- examples/step-28/step-28.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/step-28/step-28.cc b/examples/step-28/step-28.cc index 6fde76097d..91d6d8d072 100644 --- a/examples/step-28/step-28.cc +++ b/examples/step-28/step-28.cc @@ -74,6 +74,10 @@ // file: #include +// We use a little utility class from boost to save the state of an output +// stream (see the run function below): +#include + // Here are two more C++ standard headers that we use to define list data // types as well as to fine-tune the output we generate: #include @@ -1624,6 +1628,14 @@ namespace Step28 template void NeutronDiffusionProblem::run () { + // We would like to change the output precision for just this function and + // restore the state of std::cout when this function returns. + // Hence, we need a way to undo the output format change. Boost provides a + // convenient way to save the state of an output stream and restore it at + // the end of the current block (when the destructor of + // restore_flags is called) with the + // ios_flags_saver class, which we use here. + boost::io::ios_flags_saver restore_flags(std::cout); std::cout << std::setprecision (12) << std::fixed; double k_eff_old = k_eff; -- 2.39.5