cout << stack.push << fixed << setprecision(1) << x << stack.pop << endl;
Some manipulators (like setprecision()) are permanent, any change made will remain in place for the rest of the execution of the program. But I don't want to have to reset everything manually. So I wanted to be able to save the entire state of the format flags. So I added the stack.push and stack.pop manipulators to push the format flags and the precision, so that the manipulators are now effectively temporary.
NB: Does anyone have a different/better solution? I feel like I'm reinventing the wheel.
The code needed is at http://gist.github.com/968629 . You'll need to declare a variable called stack (or any other name you like) before you can use it.
#include "FormatFlagStack.cpp"
FormatFlagStack stack;
cout << stack.push << fixed << setprecision(1) << x << stack.pop << endl;
What I say is your code is correct & proper enough to solve the problem.So I suggest you to go with your code.
ReplyDelete