]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Restore std::cout flags.
authorDavid Wells <wellsd2@rpi.edu>
Thu, 16 Mar 2017 22:22:16 +0000 (18:22 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Sat, 18 Mar 2017 21:22:02 +0000 (17:22 -0400)
examples/step-28/step-28.cc

index 6fde76097d6fa18f10033319e0b7fff544d4f822..91d6d8d0720835f526f615ccf4759ab8a50464e0 100644 (file)
 // file:
 #include <deal.II/grid/grid_tools.h>
 
+// We use a little utility class from boost to save the state of an output
+// stream (see the <code>run</code> function below):
+#include <boost/io/ios_state.hpp>
+
 // 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 <list>
@@ -1624,6 +1628,14 @@ namespace Step28
   template <int dim>
   void NeutronDiffusionProblem<dim>::run ()
   {
+    // We would like to change the output precision for just this function and
+    // restore the state of <code>std::cout</code> 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
+    // <code>restore_flags</code> is called) with the
+    // <code>ios_flags_saver</code> 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;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.