C + + IO format Controller

Source: Internet
Author: User
Tags setf

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.