V
Virchanza
I have an unsigned integer variable:
unsigned x;
This variable holds the price of something where the units are "Euro
cent".
Therefore, if x is set to 1, then the price is EUR 0.01.
If x is set to 108, then the price is EUR 1.08
Anyway, I want to print this price to the screen. Is this the best
method?
cout << "EUR " << x / 100 << '.' << setw(2) << setfill('0') << x %
100;
I have a class that overloads the "ostream<< operator", so I need to
stick this line of code in the function body. Just wanna make sure I'm
going about it the best way.
I believe the difference jn doing "<< setw" instead of "cout.setw" is
that the effect of "<< setw" subsides at the end of statement, whereas
the effect of "cout.setw" is permanent. Am I right?
unsigned x;
This variable holds the price of something where the units are "Euro
cent".
Therefore, if x is set to 1, then the price is EUR 0.01.
If x is set to 108, then the price is EUR 1.08
Anyway, I want to print this price to the screen. Is this the best
method?
cout << "EUR " << x / 100 << '.' << setw(2) << setfill('0') << x %
100;
I have a class that overloads the "ostream<< operator", so I need to
stick this line of code in the function body. Just wanna make sure I'm
going about it the best way.
I believe the difference jn doing "<< setw" instead of "cout.setw" is
that the effect of "<< setw" subsides at the end of statement, whereas
the effect of "cout.setw" is permanent. Am I right?