Hi, I am learning manipulators, and I have a few questions about when to use ios::. I understand I need to use this for the manipulator to have access to its 'base' but in certain examples in my book it is not used, and i dont understand why it is not used in these examples. I have shows all the examples below. If anyone could explain, it would be appreciated.
The "showpoint" is for printing decimal values of "1.0", but I have found that when "setprecision" has a value greater than (0) it will always print ".0" because "setprecision" says to print at least 1 decimal place.
I do not know if there is a better time to use "std::ios::something" over the above code or not. What I have done is usually simple and the above code works just fine.
It may come down to how much do you want to type and how much checking you want to do when you do not remember the correct syntax.
@DonnaPin
The reason ios:: is not being used in the examples, if that is what is troubling you, it is because the dreaded usingnamespace std; line is included in your examples.
This is another good reason for not using usingnamespace std; and instead being namespace specific once you identify which namespace is appropriate ( ios:: alone vs std::ios:: )
#include <iostream>
#include <iomanip>
int main()
{
std::cout
<< std::setiosflags(std::ios::showpos)
<< std::setiosflags(std::ios::scientific)
<< 123 << " " << 123.23; //setioflags does not need ios:: but scientific does
return 0;
}