From ed33c145e3aa1b838bcafaf9ae4852d80010121b Mon Sep 17 00:00:00 2001 From: Oliver Sander <sander@dune-project.org> Date: Fri, 20 Nov 2009 16:24:52 +0000 Subject: [PATCH] Do it right: stringstreams instead of std::sprintf [[Imported from SVN: r5719]] --- dune/common/misc.hh | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/dune/common/misc.hh b/dune/common/misc.hh index fc8772a16..589f4aee5 100644 --- a/dune/common/misc.hh +++ b/dune/common/misc.hh @@ -7,8 +7,8 @@ \brief Miscellaneous helper stuff */ -#include <cstdio> #include <iostream> +#include <iomanip> #include <sstream> #include <complex> #include "exceptions.hh" @@ -112,28 +112,9 @@ namespace Dune { name << path; name << "/"; } - name << fn; + name << fn << std::setw(precision) << std::setfill('0') << ntime; - char cp[256]; - switch(precision) - { - case 2 : { std::sprintf(cp, "%02d", ntime); break; } - case 3 : { std::sprintf(cp, "%03d", ntime); break; } - case 4 : { std::sprintf(cp, "%04d", ntime); break; } - case 5 : { std::sprintf(cp, "%05d", ntime); break; } - case 6 : { std::sprintf(cp, "%06d", ntime); break; } - case 7 : { std::sprintf(cp, "%07d", ntime); break; } - case 8 : { std::sprintf(cp, "%08d", ntime); break; } - case 9 : { std::sprintf(cp, "%09d", ntime); break; } - case 10 : { std::sprintf(cp, "%010d", ntime); break; } - default : - { - DUNE_THROW(Exception, "Couldn't generate filename with precision = "<<precision); - } - } - name << cp; - - // here implicitly a string is generated + // Return the string corresponding to the stringstream return name.str(); } -- GitLab