How do I take off fixed, and precision?

I have a loop going and at the end it displays some numbers and one percent.

I want the percent rounded to two decimal places, not the other numbers.

The first time through it works fine and only the decimal displays .00

But in all the loops after that every number displays .00

and I only want it for the percent, how can I turn it off before and after the percent?

It seems that once I set the precision and fixed it stays forever.
IIRC, you can call a function that returns the current state of a stream to a special type, and use it to restore a stream to its previous form. Lemme find it.
http://www.cplusplus.com/reference/iostream/ios/rdstate/
There it is. It returns a special type, iostate. You can call
http://www.cplusplus.com/reference/iostream/ios/setstate/
with an object of type iostate to restore the flags to what it previously was. This should put the stream back to normal.

WRONG MATERIAL, iostate is for stream flags such as failbit and not manipulators.
Last edited on
Oh darn sorry I'm not sure how to do any of that yet I'm just doing an assignment for C++ class and didn't learn too much about funcions yet, there's no simple like unset or something I can use?

Thanks
Actually, I directed you to the wrong stuff. Sorry about that. I just found the stuff I was really looking for, fmtflags.
http://www.cplusplus.com/reference/iostream/ios_base/fmtflags/
That's the type you need, ios_base::fmtflags. It's a type that stores the manipulator states of the stream in question. (iostate stores the flags for the stream.) To declare, do something like this:
ios_base::fmtflags basefmt;
If you're wondering about ::, that's a scope operator. The type fmtflags is a member of the class ios_base, the starting point of the iostream class hierarchy, and therefore it must be qualified as a member of the class in question. That basically creates an object of type fmtflags.
To get the current flag set for a stream, call flags() with no arguments:
basefmt = stream.flags();
To then reset the stream to the flags, call flags() with one argument, the argument being an object of type fmtflags (the arg determines the flags that will be set):
stream.flags(basefmt);
More info: http://www.cplusplus.com/reference/iostream/ios_base/flags/

Just in case you are wondering, there is a difference between fmtflags, the thing you are looking for, and iostate, the thing that I stupidly directed you to prior... I'll clear that up so you don't confuse yourself.
Streams track errors by means of special flags, such as failbit, badbit, etc. Each of these flags (there are four, you can look them up in this site's reference) identifies a certain error. The flags will be thrown by operations that result in these errors, and you can check the flags to determine if your stream is still valid (ie, not in a state of error). Once you check the flags, you want to clear them so you can be ready to check them again. You can do that one by one, or you can preserve the flag states in an iostate with rdstate and then reset them with setstate.
Manipulators are a whole different story. They modify the way the stream handles its input and output. Manipulators all are handled through the type fmtflags, which holds the information necessary for a stream to determine the manipulators and status it should apply to its IO. You can create a package of manipulators to be applied all at once with an object of type fmtflags, and you can also use the function I told you about above, flags(), to handle fmtflags objects all at once.
Last edited on
Topic archived. No new replies allowed.