1. Functions of the IO controller that do not require parameters are defined in <iosteram>, including Dec,oct and Hex. Also includes ws,endl,ends and flush as well as the contents shown.
2, the need for parameters of the controller defined in the <iomainip> header file, like the following predefined controller
3. Below is an example program using IO Controller
1: #include <fstream>
2: #include <iomanip>
3: usingnamespace std;
4:
5: int main () {
6: ofstream TRC ("Trace.out");
7: int i = 47;
8: float f = 2300114.414159;
9: char"is there any more?";
Ten:
One : TRC << setiosflags (
/*| Ios::stdio * /// ?????
: | ios::showbase | ios::uppercase
: | ios::showpos);
: //Default to Dec
: TRC << hex << i << Endl;
: TRC << resetiosflags (ios::uppercase)
: << Oct << i << Endl;
: trc.setf (Ios::left, Ios::adjustfield);
: TRC << resetiosflags (ios::showbase)
: << Dec << setfill (' 0 ');
: "fill char:" << Trc.fill () << Endl;
At : TRC << SETW (Ten) << i << Endl;
: trc.setf (ios::right, Ios::adjustfield);
: TRC << SETW (Ten) << i << Endl;
: trc.setf (iOS::internal, Ios::adjustfield);
: TRC << SETW (Ten) << i << Endl;
: //Without SETW (TEN)
£ º
: TRC << resetiosflags (Ios::showpos)
: << setiosflags (ios::showpoint)
: "prec =" << trc.precision () << Endl;
: trc.setf (ios::scientific, Ios::floatfield);
: trc << F << Endl;
: trc.setf (iOS::fixed, Ios::floatfield);
: trc << F << Endl;
Panax notoginseng : //Automatic
: trc << F << Endl;
: TRC << setprecision (20);
Max : "prec =" << trc.precision () << Endl;
In : trc << F << Endl;
: trc.setf (ios::scientific, Ios::floatfield);
: trc << F << Endl;
: trc.setf (iOS::fixed, Ios::floatfield);
: trc << F << Endl;
: //Automatic
: trc << F << Endl;
:
In : TRC << setw << s << endl;
: TRC << setw (+) << s << Endl;
Wuyi: trc.setf (Ios::left, Ios::adjustfield);
: TRC << setw (+) << s << Endl;
:
A : TRC << resetiosflags (
: ios::showpoint | ios::unitbuf
£ º //| Ios::stdio//?????????
£ º );
: }///:~
4. Enter the following
+47
0X2F
057
Fill char:0
+470000000
0000000+47
+000000047
+47
Prec = 6
2.300115e+006
2300114.500000
2.30011e+006
Prec = 20
2300114.5000000000000
2.30011450000000000000e+006
2300114.50000000000000000000
2300114.5000000000000
Is there any more?
0000000000000000000000Is there any more?
Is there any more?0000000000000000000000
C + + IO format Controller