To start, I want to show you my code below.
#include<iostream>
int main()
{
float num = 3;
std::ios_base::fmtflags initial;
initial = std::cout.setf(std::ios_base::fixed);
std::cout.setf(initial);
std::cout<<num;
}
The output is 3.000000. With only first and last lines output is 3. My book says that "The setf() method returns a copy of all the formatting settings in effect before the call was made. std::ios_base::fmtflags is a fancy name for the type needed to store this information. So the assignment to initial stores the settings that were in place before the setf function was called. The initial variable can then be used as an argument to setf() to reset all the formatting settings to this original value." But as you can see, it doesn't work. What's the issue?
Aucun commentaire:
Enregistrer un commentaire