From: David Wells Date: Thu, 16 Mar 2017 22:22:16 +0000 (-0400) Subject: Restore std::cout flags. X-Git-Tag: v8.5.0-rc1~25^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=949818cd8b4a1c9e979ba0b2d6572d9958b198b5;p=dealii.git Restore std::cout flags. --- 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;