0

I have a issue in display string stream content. I want to make string stream containing timer time with fixed 2 numbers before and after point. To not recreate over and over i decided to make it in constructor of class that have it. I make something like this:

timerTextString << std::fixed << std::setprecision(2) << std::setw(5) << std::setfill('0');

But, when i clean it like this(I've found this in other discussions): timerTextString.str(""); it seems to clear iomanip flags. When I display this in next frame it don't have any manipulation. To make it work I must in each write use manips:

timerTextString << std::fixed << std::setprecision(2) << std::setw(5) << std::setfill('0') <<timeLeft.asSeconds();

Have you any solution? I want to no use it at any write to code look much clear and (probably) faster using that stream.

BoomboxPL
  • 1
  • 1
  • 3
    `auto flags = timerTextString.flags(); timerTextString.str(""); timerTextString.flags(flags);` – Eljay Apr 09 '20 at 13:32
  • @Eljay thanks for reply, but this don't work. It still lose iomanip – BoomboxPL Apr 09 '20 at 16:00
  • It saves/restores the flags. If you want to save/restore the precision and the width and fill, you'll have to do those as well. If you use Boost, there's the [I/O Stream State Saver](https://www.boost.org/doc/libs/1_72_0/libs/io/doc/ios_state.html). – Eljay Apr 09 '20 at 16:08
  • Both `setw` and `setfill` will have been reset if you've made some prior streaming to `timerTextString`. In order to save those states you need to do it _before_ using the stream. – Ted Lyngmo Apr 09 '20 at 17:30

0 Answers0