
                  10

                 

                  "㯭 ⮫쪮 ,  "
                             . ୨

       몥 ++  ।  -뢮.    㦭, ᪮
  ⠪ ।⢠      ⭮  ᮧ    ᠬ  몥.
  ᠭ  ⥪ ⮪ -뢮 ॠ ண
  ⨯    ⥬   䥪⨢ ᯮᮡ ᨬ쭮  
  뢮 楫, ⢥ ᥫ  ᨬ ப,  ⠪ 
    ७, ⠭  ࠡ  짮⥫᪨ ⨯
  . 짮⥫᪨ 䥩 ⥪ 室  䠩
  <iostream.h>.   饭 ᠬ ⮪ ⥪, 
  ᯮᮡ ࠡ    । ਥ ॠ樨 ⥪.

      10.1  

  ப ⭠ 㤭  ஥஢  ॠ樨
  ⠭ । -뢮  몮 ணࠬ஢.
  ࠤ樮 ।⢠ -뢮 뫨  ⠭  ᪫⥫쭮  
  讥  ᫮ ஥ ⨯ . ,  ਢ
  ணࠬ  ++   짮⥫᪨ ⨯ , ⮬
  室 ।⠢
   -뢮 祭 ⠪ ⨯. 祢,  ।⢠
  -뢮   묨, 㤮묨, 묨  ᯮ짮
  ,   ᥣ, 묨.    襫 襭, ஥
  㤮⢮ਫ  ; ⮬ 室   짮⥫
  ᮧ  ।⢠ -뢮,  ⠪  ⠭
  ।⢠ -뢮    । ਬ.
      ᮧ ++ 뫠  ⮬, ⮡ 짮⥫  । 
  ⨯ , ࠡ  묨 뫠  ⮫  㤮  䥪⨢ 
    ஥묨 ⨯.  ࠧ,  ࠧ㬭 ॡ,
  ⮡ ।⢠ -뢮  ++ ணࠬ஢  ᯮ짮
  ⥩ ++, 㯭 . ।⠢  ⮪
  ।⢠ -뢮   १ ⪨ 㤮⢮
  ⨬ ॡ.
  ᭮  ⮪ । -뢮 -  
  ८ࠧ ꥪ⮢ । ⨯  ᫥⥫쭮 ᨬ
   .   㣨 奬 -뢮,  㪠 
  ᭮,  ᫨  ᨬ  ஬ ⮢,  
  ⢥   䠢⮬,   奬 筮 -뢮
   ᢥ  . ⮬ ணࠬ᪠   ᢮ 
  ᠭ 裡  ꥪ⮬ । ⨯  ⨯ (
  ⢥) ப.
    ᫥騥 ࠧ 뢠 ᭮  ⮪ ⥪ ++:
  10.2 뢮: ,   ਪ ணࠬ ।⠢ 뢮,
        ᠬ   ८ࠧ ⠪  ꥪ⮢    int,
       char *, complex  Employee_record  ᫥⥫쭮 ᨬ.
       뢠 ।⢠   ꥪ⮢ ஥ 
       짮⥫᪨ ⨯ .
  10.3 : ᠭ 㭪樨   ᨬ, ப  祭
       ஥  짮⥫᪨ ⨯ .
  10.4 ଠ஢:   । ॡ  
       뢮, ਬ, int   묨 ࠬ,
       㪠⥫  ⭠筮 ,  ⢥ ᫠ 
            筮 䨪஢ ࠧ.
       㦤 㭪樨 ଠ஢  । ணࠬ᪨
       ਥ  ᮧ,  ⭮, .
  10.5   ⮪:   ணࠬ  ++    ᯮ짮  
       㬮砭  ⮪ - ⠭ 뢮 (cout), ⠭ 
       (cin)  ⠭ ⮪ 訡 (cerr). ⮡ ࠡ  -
        ன⢠  䠩  ᮧ ⮪  ਢ易 
        ⨬ ன⢠  䠩. 뢠 堭  
        䠩  뢠 䠩  ⮪.
  10.6 -뢮  : 㦤 㭪 printf  䠩 <stdio.h>
          ⠪   ⥪    <iostream.h> 
       ++.
  ,    ᨬ ॠ権
  ⮪ ⥪ -뢮   ।, ᠭ , 㤥
  ⮫쪮 ⢮ ।,   襩 ⥪. ,
     让 ணࠬ  쪠  ணࠬ,  
  ६ ࢠ .  ⮩  ।ਭ ⪠ 
   ࠧ  ⮪ ⥪ -뢮,  
  業 ᭮ 楯樨 ⮪ -뢮  
    묨 ।⢠. ᯮ ⮫쪮 ।⢠,
  ᠭ ,     ணࠬ; ᫨ 
  室   ᫮ ।⢠,   ⠫ﬨ  襬
  㪮  ++.  䠩 <iostream.h> । 䥩
  ⮪ ⥪.  ࠭  ⮪ ⥪ ᯮ짮
  䠩 <stream.h>. ᫨   䠩, <iostream.h> । 
   ।,  <stream.h> । ⢮, ஥
  ᮢ⨬  ࠭,  묨 ⮪묨 ⥪.
     ⢥,  짮 ⮪ ⥪   㦭
   孨  ॠ樨, ⥬ ,  孨  
  ࠧ筮  ࠧ ॠ権. , ॠ -뢮
   祩, 饩 । ᫮,  ਥ, 
     襭,  ਬ   㣨 ,  ᠬ 
  襭 ⮩ 祭.

     10.2 

  ண ⨯    ࠧ  ࠡ   ஥묨,  ⠪  
  짮⥫᪨ ⨯    ᯥ,  ᫨ ᯮ짮
  ⢥ ॣ㦥  㭪樨  ࠧ 権 뢮.
  ਬ:

       put(cerr,"x = "); // cerr - 室 ⮪ 訡
       put(cerr,x);
       put(cerr,'\n');

   㬥 ।  㭪  뢠   砥.
   室 ਬ  ᪮쪨 몠, ,  ᫨誮
   .   ॣ㧪 樨 << , ⮡  砫
  "뢥" ("put to"),       ࠧ
  ணࠬ 뢮    ᫥⥫쭮 ꥪ⮢,
  ਬ ⠪:

      cerr << "x = " << x << '\n';

   cerr 砥 ⠭ ⮪ 訡. , ᫨  ⨯ int
   祭 123,  ਢ  뤠

      x = 123

    ᨬ  ப  ⠭ ⮪ 訡. 筮, ᫨ 
   짮⥫᪨ ⨯ complex  祭 (1,2.4),  㪠
   뤠

      x = (1,2.4)

   ⮪ cerr.  室  ᯮ짮  x ⠪ ⨯, 
  ண ।  <<,   짮⥫  
  । <<   ⨯.
       ᯮ짮  뢮, ⮡  ᫮,
  , ᫨ ਬ 㭪 뢮.  祬  ᨬ << ?
     ᥬ (.  7.2).  ⮬   
  뢮 뫠  ᢠ,  設⢮  ।⠥,
  ⮡ 樨   뢮 뫨 ࠧ.  ⮣, 冷
  믮 樨 = 室騩, ⠪ cout=a=b 砥 cout=(a=b).
  ஡ ᯮ짮 樨 <  >,    ⠪ ९ ਢ易
  ⨥ " 祬"  " 祬",  樨 -뢮  
    ࠪ᪨    ⥭.
      樨 <<  >> 宦  ᮧ ⠪ ஡.  ᨬ,
    ਯ뢠   ""  "".   ⭮  
    ᯮ㥬 権  ஥묨 ⨯, 
  ਮ << 筮 , ⮡  䬥᪨ ࠦ 
  ⢥ ࠭  ᪮:

       cout << "a*b+c=" << a*b+c << '\n';

   㦭, ᫨ ࠦ ᮤন 樨   
  ਮ⮬:

       cout << "a^b|c=" << (a^b|c) << '\n';

   ᤢ   ᯮ짮  樨 뢮, , 筮,
      ᪮:

       cout << "a<<b=" << (a<<b) << '\n';

  10.2.1 뢮 ஥ ⨯

    ࠢ 뢮 ஥ ⨯ ।  ostream
   樥 << (뢥):

       class ostream : public virtual ios {
           // ...
       public:
          ostream& operator<<(const char*);    //ப
          ostream& operator<<(char);
          ostream& operator<<(short i)
            { return *this << int(i); }
          ostream& operator<<(int);
          ostream& operator<<(long);
          ostream& operator<<(double);
          ostream& operator<<(const void*);    // 㪠⥫
           // ...
    };

  ⢥,   ostream    㭪権 operator<<()
   ࠡ  묨 ⨯.
       㭪 operator<< 頥 뫪   ostream, 
  ண  뢠, ⮡    뫮 ਬ  ࠧ
  operator<<. , ᫨  ⨯ int, 

         cerr << "x = " << x;

   

         (cerr.operator<<("x = ")).operator<<(x);

   ⭮,  砥,  ᫨ ᪮쪮 ꥪ⮢ 뢮 
     뢮,    뤠 
  ⢥ 浪: ᫥ - ࠢ.
        㭪 ostream::operator<<(int) 뢮 楫 祭, 
  㭪 ostream::operator<<(char) - ᨬ. ⮬ 㭪

        void val(char c)
        {
          cout << "int('"<< c <<"') = " << int(c) << '\n';
        }

  ⠥ 楫 祭 ᨬ    ணࠬ

        main()
        {
          val('A');
          val('Z');
        }

  㤥 ⠭

        int('A') = 65
        int('Z') = 90

   । ஢ ᨬ ASCII,  襩 設  
   १.  ,  ᨬ쭠 ⠭ 
  ⨯ char, ⮬ cout<<'Z' ⠥ 㪢 Z,    楫 90.
        㭪 ostream::operator<<(const void*) ⠥ 祭
  㪠⥫  ⠪ ,   室  ᯮ㥬
  ⥬ 樨.
  ணࠬ

        main()
        {
         int i = 0;
         int* p = new int(1);
         cout << "local " << &i
              << ", free store " << p << '\n';
        }

   뤠  設, ᯮ㥬 ஬,

        local 0x7fffead0, free store 0x500c

   㣨 ⥬ 樨    ᮣ襭  ࠦ
  祭 㪠⥫.
      㦤   ios ⫮  10.4.1.

  10.2.2 뢮 짮⥫᪨ ⨯

  ᬮਬ 짮⥫᪨ ⨯ :

       class complex {
          double re, im;
       public:
          complex(double r = 0, double i = 0) { re=r; im=i; }

          friend double real(complex& a) { return a.re; }
          friend double imag(complex& a) { return a.im; }

          friend complex operator+(complex, complex);
          friend complex operator-(complex, complex);
          friend complex operator*(complex, complex);
          friend complex operator/(complex, complex);
          //...
       };

    ⨯ complex  <<  । ⠪:

      ostream& operator<<(ostream&s, complex z)
      {
       return s << '(' real(z) << ',' << imag(z) << ')';
      };

   ᯮ짮   operator<<  ஥ ⨯. ਬ,

      main()
      {
          complex x(1,2);
          cout << "x = " << x << '\n';
      }

  뤠

      x = (1,2)

   । 樨 뢮  짮⥫᪨ ⨯ 
   㦭 ஢ ᠭ  ostream,  ॡ  
   ࠬ ,   ᠭ . ᫥ 祭 ,
  ᪮ ᠭ  ostream 室 । ⠭
   䠩,        設⢠
  짮⥫,       ,  ᫨ 
  .     ⮩ 稭,     砩 
    . ஬ ⮣   
  ॠ ostream,  ࠣ 짮⥫᪨ ணࠬ.

  10.3 

     室  뢮.   istream,  ॠ
    >> (" " - "input from")  讣 
  ⠭ ⨯.  짮⥫᪨ ⨯  । 㭪
  operator>>.

  10.3.1  ஥ ⨯

   istream । ᫥騬 ࠧ:

       class istream : public virtual ios {
           //...
       public:
           istream& operator>>(char*);     // ப
           istream& operator>>(char&);     // ᨬ
           istream& operator>>(short&);
           istream& operator>>(int&);
           istream& operator>>(long&);
           istream& operator>>(float&);
           istream& operator>>(double&);
           //...
       };

  㭪樨  operator>> । ⠪:

       istream& istream::operator>>(T& tvar)
       {
        // ய᪠ 饭 ஡
        // - ࠧ ⠥ T `tvar'
         return *this;
        }

      VECTOR ᫥⥫쭮 楫, ࠧ塞
  ஡,   㭪樨:

      int readints(Vector<int>& v)
      // 頥 ᫮ ⠭ 楫
      {
         for (int i = 0; i<v.size(); i++)
         {
            if (cin>>v[i]) continue;
            return i;
         }
         // ᫨誮  楫  ࠧ Vector
         // 㦭 ᮮ⢥ ࠡ⪠ 訡
       }

   祭  ⨯, ⫨  int, ਢ  ४饭
  樨 ,  横  蠥. , ᫨  

       1 2 3 4 5. 6 7 8.

   㭪 readints() ⠥  楫 ᥫ

       1 2 3 4 5

   窠 ⠭  ᨬ, 騬 .  ஡,
   ।  ⠭ ,  饭 ஡, ..
  ஡, ⠡,  ப, ॢ ப   ⪨.
  ஢ઠ  饭 ஡    㭪樨 isspace()
   䠩 <ctype.h>.
        ⢥ ୠ⨢  ᯮ짮 㭪樨 get():

      class istream : public virtual ios {
          //...
          istream& get(char& c);                     // ᨬ
          istream& get(char* p, int n, char ='n');   // ப
      };

    饭 ஡ ᬠਢ   㣮 ᨬ 
   ।祭  ⠪ 権 ,    
  ।   ᨬ.
       㭪 istream::get(char&)   ᨬ  ᢮ ࠬ.
  ⮬ ணࠬ ᨬ쭮 ஢   ⠪:

       main()
       {
         char c;
         while (cin.get(c)) cout << c;
       }

    룫廊 ᨬ筮,   樨 >>  뢮 ᨬ
      put(), ⠪     ⠪:

       main()
       {
          char c;
          while (cin.get(c)) cout.put(c);
       }

  㭪  ६ ࠬࠬ istream::get()   ᨬ 
    n ᨬ, 稭   p.  类 饭  get()
   ᨬ, 饭   (᫨  뫨),  0, ⮬
  ᫨ ன ࠬ ࠢ n,     n-1 ᨬ. ⨩
  ࠬ । ᨬ, 騩 . 筮 ᯮ짮
  㭪樨 get()  ६ ࠬࠬ ᢮  ⥭ ப  
   ࠧ   쭥襣 ࠧ, ਬ ⠪:

       void f()
       {
           char buf[100];
           cin >> buf;                 // ⥫쭮
           cin.get(buf,100,'\n');      // 
           //...
        }

   cin>>buf ⥫쭠, ᪮ ப   祬 99
  ᨬ ९ . ᫨ 㦥 騩 ᨬ,  
  ⠥  ⮪  ᨬ 騬 .  
  ஢   ९:

       void f()
       {
          char buf[100];

          cin.get(buf,100,'\n');   // 

          char c;
          if (cin.get(c) && c!='\n') {
             // 室 ப , 祬 
          }
          //...
        }

  ⢥,   get()  ⨯ unsigned char.
        ⠭⭮ 筮 䠩 <ctype.h> । ᪮쪮
  㭪権,   ࠡ⪨  :

       int isalpha(char)   // 'a'..'z' 'A'..'Z'
       int isupper(char)   // 'A'..'Z'
       int islower(char)   // 'a'..'z'
       int isdigit(char)   // '0'..'9'
       int isxdigit(char)  // '0'..'9' 'a'..'f' 'A'..'F'
       int isspace(char)   // ' ' '\t' 頥  ப
                           //  ॢ ଠ
       int iscntrl(char)   // ࠢ騩 ᨬ  
                           // (ASCII 0..31  127)
       int ispunct(char)   //  㭪樨, ⫨祭  ਢ 
       int isalnum(char)   // isalpha() | isdigit()
       int isprint(char)   // : ascii ' '..'~'
       int isgraph(char)     // isalpha() | isdigit() | ispunct()
       int isascii(char c)   { return 0<=c && c<=127; }

   , ஬ isascii(), ࠡ   ⮣ ᬮ,
  ᯮ ᨬ    ⠡ ਡ⮢ ᨬ. ⮬
   ࠦ ⨯

       (('a'<=c && c<='z') || ('A'<=c && c<='Z')) // 㪢

  ஥  ⮫쪮 ⮬⥫쭮 ,      訡
  ( 設  ஢ EBCDIC    ⮫쪮 㪢), 
  ᯮ짮 맮 ⠭⭮ 㭪樨 isalpha(),   ⮬
    䥪⨢.
   ⢥ ਬ ਢ 㭪 eatwhite(),  ⠥ 
  ⮪ 饭 ஡:

       istream& eatwhite(istream& is)
       {
            char c;
            while (is.get(c)) {
                if (isspace(c)==0) {
                    is.putback(c);
                    break;
                }
             }
             return is;
        }

    ᯮ 㭪 putback(),  頥 ᨬ 
  ⮪,   ⠭  騬 ⥭.

  10.3.2 ﭨ ⮪

    ⮪ (istream  ostream) 易 । ﭨ.
  ⠭ 樨  訡 ࠡ뢠   ஢ન 
  ⠭ ﭨ 室騬 ࠧ.
   ﭨ ⮪    権  ᮬ ios:

       class ios { //ios    ostream  istream
           //...
       public:
           int eof() const;     // 諨   䠩
           int fail() const;    // ᫥  㤥 㤠筠
           int bad() const;     // ⮪ ᯮ祭
           int good() const;    // ᫥  㤥 ᯥ譮
           //...
       };

  ᫥   ⠥ ᯥ譮, ᫨ ﭨ 
  good()  eof(). ᫨ ﭨ  good(),  ᫥
      ᯥ譮,  ⨢ 砥  㤥
  㤠筮. ਬ 樨   ⮪  ﭨ, 
   good(), ⠥ ⮩ 樥. ᫨ ந諠 㤠 
  ⪥ ⥭  ६ v,  祭 v   ( 
  , ᫨ v  ⨯, ࠢ塞 㭪ﬨ 童  istream
   ostream). 稥  ﭨﬨ, 묨  fail() 
   bad() 㫮 㤭,     ⮫쪮  ࠧࠡ稪
  権 . ᫨ ﭨ  fail(),  ⠥,  ⮪
   ०,   ᨬ  ய;  ﭨ bad() 祣
  ᪠ .
      祭, 騥  ﭨ, ।   ios:

       class ios {
           //...
       public:
           enum io_state {
               goodbit=0,
               eofbit=1,
               filebit=2,
               badbit=4,
           };
           //...
       };

  ⨭ 祭 ﭨ   ॠ樨,  㪠 祭
  ਢ ⮫쪮, ⮡  ᨭ⠪᪨ ࠢ 権.
   ஢ ﭨ ⮪  ᫥騬 ࠧ:

       switch (cin.rdstate()) {
       case ios::goodbit:
           // ᫥   cin 뫠 ᯥ譮
           break;
       case ios::eofbit:
           //   䠩
           break;
        case ios::filebit:
           //   訡
           //  宩
           break;
         case ios::badbit:
           //  cin  ᯮ祭
           break;
         }

    ࠭ ॠ  祭 ﭨ ᯮ짮
   .  ਢ  ⥫쭮 ७
  ࠭⢠ , ⮬   㯭 ⮫쪮  ।
   ios. ᫨  室 ᯮ짮    ⠭ 
   ⥪,  ᯮ짮 ᫥騬 ।ﬨ:

       const int _good = ios::goodbit;
       const int _bad = ios::badbit;
       const int _file = ios::filebit;
       const int _eof = ios::eofbit;

       typedef ios::io_state state_value ;

  ࠡ稪 ⥪    ⮬, ⮡  
     쭮 ࠭ . ᫨ 
  ᫥ 室  騩 䥩 ⥪,  ᥣ
   ᯮ짮    䨪ᠬ, ਬ,  ios::goodbit
   ios::io_state.
         ६  ⨯,  ண । 樨
  <<  >>, 横 ஢ 뢠 ᫥騬 ࠧ:

        while (cin>>z) cout << z << '\n';

  ᫨ ⮪   ᫮,  ஢ ﭨ ⮪, 
  ᫮ 믮 (.. १   0) ⮫쪮  ﭨ
  good().  ࠧ  ਢ  横 ஢ ﭨ ⮪
  istream,   १⮬ 樨 cin>>z. ⮡ 㧭,
  祬 ந諠 㤠  横  ᫮,  ஢ ﭨ.
   ஢ઠ  ⮪ ॠ   樨
  ਢ (7.3.2).
     , ᫨ z  ᨬ ஬,   ਢ 横
  ⠥ ⠭   뤠   ப ⠭⭮
  뢮   ᫮ (.. ᫥⥫쭮 ᨬ,  
  饭묨 ஡). ᫨ z  ⨯ complex,   ⮬ 横
    権, ।  10.2.2  10.2.3,  ஢
   ᫠.  㭪 ஢  ⮪ 
  祭ﬨ ந쭮 ⨯   ᫥騬 ࠧ:

       complex z;
       iocopy(z,cin,cout);    // ஢ complex

       double d;
       iocopy(d,cin,cout);    // ஢ double
       char c;
       iocopy(c,cin,cout);    // ஢ char

      ᪮  ஢  ४⭮   -
  뢮,  ࠭ 筨 訡     
  ணࠬ,  ⠪ ஫ ⢥. 筮 樨 뢮 
  ஢,      㤠筮. ⮪ -
  뢮 ࠧࠡ뢠  ⮣ ਭ樯, ⮡ ᤥ ᪫⥫
  樨 㯭묨,  ⥬ ᠬ  ࠡ 訡
    -뢮.

  10.3.3  짮⥫᪨ ⨯

     짮⥫᪮ ⨯  ।  筮
  ⠪ ,    뢮,   樨  ⢥, ⮡
  ன ࠬ  ⨯ 뫪, ਬ:

       istream& operator>>(istream& s, complex& a)
       /*
          ଠ input ⠭  complex; "f" 砥 float:
              f
              ( f )
              ( f , f )
       */
       {
          double re = 0, im = 0;
          char   c = 0;

          s >> c;
          if (c == '(') {
              s >> re >> c;
              if (c == ',') s >> im >> c;
              if (c != ')') s.clear(ios::badbit); // ⠭ ﭨ
          }
          else {
              s.putback(c);
              s >> re;
          }

          if (s) a = complex(re,im);
          return s;
       }

  ᬮ  ᦠ , ࠡ뢠饣 訡,  ᠬ 
  뢠   訡. 樠 쭮 ६
   㦭  ⮣, ⮡     砩 祭, ਬ
  '(',  砥 㤠筮 樨. ᫥ ஢ઠ ﭨ ⮪
  ࠭,  ࠬ a  祭 ⮫쪮  ᯥ譮 .
       , ⠭ ﭨ ⮪,  clear()
  ( clear - , ࠢ),
  ᪮  ᥣ  ᯮ  ⠭ ﭨ ⮪
   good(); 祭  㬮砭  ࠬ ios::clear() 
  ios::goodbit.

  10.4 ଠ஢

   ਬ  10.2 ᮤঠ ଠ஢ 뢮,  
  ८ࠧ ꥪ  ᫥⥫쭮 ᨬ, 
  ⠭묨 ࠢ,  ன ⠪ । ⨬
  ࠢ.  ணࠬ⠬ ॡ  ࠧ .
  ,  ॡ ஫஢ ࠧ , 室
   樨 뢮,  ଠ, ᯮ㥬  뤠 ᥫ.
  筮 ⠪  ⨬ ࠢ 묨 ᯥ⠬ .

  10.4.1  ios

  設⢮ । ࠢ -뢮 ।祭  
  ios,     ostream  istream.   
  室 ࠢ   istream  ostream  ஬,
  ᯮ㥬  権 -뢮.    ios ஫:
   ᨬ       롨 㤠. ,  
  ios  童, ᮤঠ騩 ଠ  ᯮ㥬  ⥭ 
   楫 ᥫ ⥬ ᫥ (筠, 쬥筠 
  ⭠筠),   筮  ⢥ ᥫ  ..,  ⠪
  㭪樨  ஢ન  ⠭ 祭 ६, ࠢ
  ⮪.

       class ios {
           //...
       public:
           ostream* tie(ostream* s);   // 易 input  output
           ostream* tie();             //  "tie"

       int width(int w);               // ⠭  width
       int width() const;

       char fill(char);                // ⠭ ᨬ 
       char fill() const;              //  ᨬ 

       long flags(long f);
       long flags() const;

       long setf(long setbits, long field);
       long setf(long);
       long unsetf(long);

       int precision(int);             // ⠭ 筮  float
       int precision() const;
       int rdstate(); const;          // ﭨ ⮪, . $$10.3.2
       int eof() const;
       int fail() const;
       int bad() const;
       int good() const;
       void clear(int i=0);

       //...
    };

   10.3.2 ᠭ 㭪樨, ࠡ騥  ﭨ ⮪, ⠫
  ਢ .

  10.4.1.1 뢠 ⮪

  㭪 tie()  ⠭  ࠧࢠ   ostream 
  istream. ᬮਬ ਬ:

         main()
         {
           String s;
           cout << "Password: ";
           cin >> s;
           // ...
          }

    ࠭஢,  ਣ襭 Password:  
  ࠭ ०, 祬 믮  ⥭? 뢮  cout  
   cin ਧ, 祬 ᨬ, ⮬ Password: 
  ⮫쪮  襭 ணࠬ,  ஥  뢮.
       襭 ⮨  ⮬, ⮡ 易 cout  cin  
  樨 cin.tie(cout).
  ᫨ ostream 易  ⮪ istream,   뢮 뤠 
   樨   istream.  樨

          cout << "Password: ";
          cin >> s;

  

          cout << "Password: ";
          cout.flush();
          cin >> s;

  饭 is.tie(0) ࠧ뢠   ⮪ is  ⮪, 
     易, ᫨ ⠪ .  㣨 ⮪
  㭪, ⠭騬 । 祭, tie(s) 頥
  ।饥 祭, .. 祭 易 ⮪ । 饭
   0. 맮  ࠬ tie() 頥 ⥪饥 祭.

  10.4.1.2  뢮

  㭪 width() ⠭ 쭮 ᫮ ᨬ, ᯮ饥
   ᫥饩 樨 뢮 ᫠  ப.   १
  ᫥ 権

          cout.width(4);
          cout << '(' << 12 << ')';

  稬 ᫮ 12   ࠧ஬ 4 ᨬ, ..

          (  12)

    묨 ᨬ  ࠢ  ⠭ 
   㭪樨 fill(), ਬ:

          cout.width(4);
          cout.fill('#');
          cout << '(' << "ab" << ')';

  ⠥

          (##ab)

   㬮砭   ஡,  ࠧ   㬮砭
   0,  砥 "⮫쪮 ᨬ, ᪮쪮 㦭".  ࠧ
   ⠭⭮ 祭    맮

          cout.width(0); // ``⮫쪮 ᨬ, ᪮쪮 ''

  㭪 width()  쭮 ᫮ ᨬ. ᫨  
  ᨬ,   ⠭ , ⮬

          cout.width(4);
          cout << '(' << "121212" << ")\n";

  ⠥

          (121212)

  稭,  ன ࠧ襭 ९ ,   祭 뢮,
   ⮬, ⮡  ᠭ  뢮.   ࠢ
  뤠, 룫 ᨢ, 祬 ᨢ 뤠, 
  ࠢ쭮.
        맮 width()  ⮫쪮   ᫥   
  뢮, ⮬

          cout.width(4);
          cout.fill('#');
          cout << '(' << 12 << "),(" << '(' <<12 << ")\n";

  ⠥

          (##12),(12)

   

          (##12),(##12)

    뫮  . , ,  ᫨  ﭨ
  ࠭﫮   樨 뢮 ᥫ  ப, 稫 
     १:

          (##12#),(##12#
          )

    ⠭⭮ ,   10.4.2.1,  
  ⭮  ࠧ  뢮.

  10.4.1.3 ﭨ ଠ

    ios ᮤন ﭨ ଠ, ஥ ࠢ
  㭪ﬨ flags()  setf().    㭪樨 㦭, ⮡
  ⠭  ⬥ ᫥騥 䫠:

       class ios {
       public:
              // ࠢ騥 ଠ⮬ 䫠:
          enum {
              skipws=01,          // ய 饭 ஡  input
                                  //  ࠢ:
              left=02,            //  । 祭
              right=04,           //  ᫥ 祭
              internal=010,       //     祭
                                  // ᭮ 楫:
              dec=020,            // 쬥筮
              oct=040,            // 筮
              hex=0100,           // ⭠筮
              showbase=0200,      //  ᭮ 楫
              showpoint=0400,     // 뤠 㫨  
              uppercase=01000,    // 'E', 'X' ,   'e', 'x'
              showpos=02000,      //  '+'  ⥫ ᥫ
                                  //  ᫠ ⨯ float:
              scientific=04000,   // .dddddd Edd
              fixed=010000,       // dddd.dd
                                  //   室 ⮪:
              unitbuf=020000,     // ᫥  樨
              stdio=040000        // ᫥  ᨬ
           };
           //...
       };

   䫠 㤥 ࠧ᭥  ᫥ ࠧ. 
  祭 䫠   ॠ樨    ⮫쪮  ⮣,
  ⮡  ᨭ⠪᪨  権.
         । 䥩   䫠  権  
  ⠭  ⬥ -  業 ६,   ᪮쪮
  ॢ訩 ਥ. ᭮  ⮨⢮  ⮬,  짮⥫
   ᮡ   䫠, ਬ, ⠪:

         const int my_io_options =
            ios::left|ios::oct|ios::showpoint|ios::fixed;

   ⢮ 䫠    ࠬ  樨

         cout.flags(my_io_options);

   ⠪  ।  㭪ﬨ  ணࠬ:

         void your_function(int ios_options);

         void my_function()
         {
            // ...
           your_function(my_io_options);
           // ...
         }

  ⢮ 䫠  ⠭   㭪樨 flags(), ਬ:

         void your_function(int ios_options)
         {
          int old_options = cout.flags(ios_options);
          // ...
          cout.flags(old_options);  // reset options
          }

  㭪 flags() 頥 ஥ 祭 ⢠ 䫠. 
   ⠭ 祭  䫠,   ,
   ⠪  祭 ⤥쭮 䫠. ਬ 맮

         myostream.flags(myostream.flags()|ios::showpos);

  ⠢  myostream 뤠 ⥫ ᫠  
  + ,    ६,   祭 㣨 䫠. 砥
  ஥ 祭 ⢠ 䫠,  ஬   
  樨 | 䫠 showpos. 㭪 setf()    ᠬ,
  ⮬ ⭠   

         myostream.setf(ios::showpos);

  ᫥ ⠭ 䫠 ࠭ 祭   ⬥.
         -⠪ ࠢ -뢮   ⠭  ⬥
  䫠 - 㡮  饥  訡 襭. ᫨ ⮫쪮  ⥫쭮
    ᢮ ࠢ筮 㪮⢮   㤥 ਬ 䫠
  ⮫쪮   ,     ᫥ ࠧ, 
   ᯮ짮  (ᠭ  10.4.2.1). ਥ ࠡ
   ﭨ ⮪    ਬ ॠ樨 , 祬
   䥩 .

  10.4.1.4 뢮 楫

  ਥ   祭 ⢠ 䫠   樨 | 
  㭪権 flags()  setf() ࠡ⠥ ⮫쪮 ⮣,    ।
  祭 䫠.  ⠪    ⥬ ᫥ 楫
    뤠 ⢥.  祭, ।饥  뤠,
     ⮬  樥 ⤥ ⮢.
       襭, ਭ⮥  <iostream.h>, ᢮  ᯮ짮
  ᨨ 㭪樨 setf(), ࠡ饩   "ᥢࠬ஬", 
  뢠   䫠  ⨬    祭.

  ⮬ 饭

         cout.setf(ios::oct,ios::basefield); // 쬥筮
         cout.setf(ios::dec,ios::basefield); // 筮
         cout.setf(ios::hex,ios::basefield); // ⭠筮

  ⠭ ⥬ ᫥,  ࠣ 㣨 ⮢ ﭨ
  ⮪. ᫨ ⥬ ᫥ ⠭,  ᯮ  
  ⠭, ⮬

       cout << 1234 << ' ';  // 筮  㬮砭
       cout << 1234 << ' ';

       cout.setf(ios::oct,ios::basefield);  // 쬥筮
       cout << 1234 << ' ';
       cout << 1234 << ' ';

       cout.setf(ios::hex,ios::basefield);  // ⭠筮
       cout << 1234 << ' ';
       cout << 1234 << ' ';

  ⠥

         1234 1234 2322 2322 4d2 4d2

  ᫨  室 㪠뢠 ⥬ ᫥  
  뤠 ᫠, ᫥ ⠭ 䫠 showbase. ⮬, 
  । ਢ묨  饭ﬨ

         cout.setf(ios::showbase);

   稬

         1234 1234 02322 02322 0x4d2 0x4d2

  ⠭ , ਢ  $$10.4.2.1, । 
   ᯮᮡ । ⥬ ᫥  뢮 楫.

  10.4.1.5 ࠢ 

    饭  setf()  ࠢ ᯮ ᨬ
   । :

         cout.setf(ios::left,ios::adjustfield);     // 
         cout.setf(ios::right,ios::adjustfield);    // ࠢ
         cout.setf(ios::internal,ios::adjustfield); // ७

  㤥 ⠭ ࠢ   뢮, ।塞 㭪樥
  ios::width(), 祬  ࠣ 㣨 ⮢ ﭨ ⮪.
         ࠢ   ᫥騬 ࠧ:

       cout.width(4);
       cout << '(' << -12 << ")\n";

       cout.width(4);
       cout.setf(ios::left,ios::adjustfield);
       cout << '(' << -12 << ")\n";

       cout.width(4);
       cout.setf(ios::internal,ios::adjustfield);
       cout << '(' << -12 << "\n";

   뤠

         ( -12)
         (-12 )
         (- 12)

  ᫨ ⠭ 䫠 ࠢ internal (७),  ᨬ
      稭.  , ⠭ 
  ࠢ ࠢ.

  10.4.1.6 뢮  ᥫ.

  뢮 ⢥ 稭 ⠪ ࠢ   㭪権,
  ࠡ  ﭨ ⮪.  ⭮, 饭:

         cout.setf(ios::scientific,ios::floatfield);
         cout.setf(ios::fixed,ios::floatfield);
         cout.setf(0,ios::floatfield);   //   ⠭⭮

  ⠭   ⢥ ᥫ   㣨
  ⮢ ﭨ ⮪.
  ਬ:

       cout << 1234.56789 << '\n';

       cout.setf(ios::scientific,ios::floatfield);
       cout << 1234.56789 << '\n';

       cout.setf(ios::fixed,ios::floatfield);
       cout << 1234.56789 << '\n';

  ⠥

         1234.57
         1.234568e+03
         1234.567890

  ᫥ 窨 ⠥ n ,    饭

         cout.precision(n)

   㬮砭 n ࠢ 6. 맮 㭪樨 precision    樨
  -뢮  ⢥묨  ᫥饣 饭  precision,
  ⮬

       cout.precision(8);
       cout << 1234.56789 << '\n';
       cout << 1234.56789 << '\n';

       cout.precision(4);
       cout << 1234.56789 << '\n';
       cout << 1234.56789 << '\n';

  뤠

        1234.5679
        1234.5679
        1235
        1235

  ,  ந室 㣫,   뢠 ஡ .
        ⠭ ,   $$10.4.2.1, ।
    ᯮᮡ  ଠ 뢮 ⢥.

  10.4.2 

          ⭮ ࠧࠧ 樨,  室
  ਬ ࠧ ।  ࠧ ᫥ 樨 -뢮. ਬ:

        cout << x;
        cout.flush();
        cout << y;

        cin.eatwhite();
        cin >> x;

  ᫨  ⤥   ,  ᪠  
  ࠬ 祢,  ᫨ ﭠ ᪠ , ணࠬ
  㤭 .
         ஢  ⠪ 樨  flush() 
  eatwhite() אַ ⠢  ᯨ᮪ 権 -뢮. ᬮਬ
   flush().  ।   樥 operator<<(), 
  ஬ 뢠 flush():

        class Flushtype { };

        ostream& operator<<(ostream& os, Flushtype)
        {
           return flush(os);
        }

  । ꥪ ⠪ ⨯

        Flushtype FLUSH;

    뤠 , 稢 FLUSH  ᯨ᮪ ꥪ⮢, 
  뢮:

        cout << x << FLUSH << y << FLUSH ;

   ⠭    ﬨ 뢮  뢠
  . , 쭮   ।   ꥪ 
   樨,   ⨬ ਬ  筮 樨 뢮.
   ,  㯨 . ᬮਬ ⠪ 㭪:

          typedef ostream& (*Omanip) (ostream&);

          ostream& operator<<(ostream& os, Omanip f)
          {
            return f(os);
          }

    뢮 ᯮ ࠬ ⨯ "㪠⥫  㭪,
   㬥 ostream&   ostream&". ⬥⨢,  flush()
   㭪 ⨯ "㭪  㬥⮬ ostream&  
  ostream&",   

          cout << x << flush << y << flush;

  稢 맮 㭪樨 flush().  ᠬ   䠩 <iostream.h>
  㭪 flush() ᠭ 

          ostream& flush(ostream&);

       operator<<,  ᯮ 㪠⥫ 
  㭪,  㪠 :

          class ostream : public virtual ios {
             // ...
          public:
            ostream& operator<<(ostream& ostream& (*)(ostream&));
            // ...
          };

   ਢ  ப  ⠫  ⮪ cout  
  室饥 ६:

          cout << x << flush << y << flush;

  宦 ।     istream:

          istream& ws(istream& is ) { return is.eatwhite(); }

          class istream : public virtual ios {
           // ...
          public:
            istream& operator>>(istream&, istream& (*) (istream&));
            // ...
          };

  ⮬  ப

          cin >> ws >> x;

  ⢨⥫쭮 饭 ஡  ࠭  ⪨ ⥭  x.
  , ᪮  㬮砭  樨 >>  ஡ "ꥤ" 
  ⠪,  ਬ ws() 筮.
          室 ਬ    ࠬࠬ. ਬ,
      

          cout << setprecision(4) << angle;

   祭 ⢥ ६ angle  筮 
    ᫥ 窨.
           ⮣ 㦭 㬥 뢠 㭪,  ⠭
  祭 ६, ࠢ饩  ⮪ 筮 ⢥.
   ⨣, ᫨ । setprecision(4)  ꥪ, 
   "뢮"   operator<<():

       class Omanip_int {
           int i;
           ostream& (*f) (ostream&,int);
       public:
           Omanip_int(ostream& (*ff) (ostream&,int), int ii)
               : f(ff), i(ii) { }
           friend ostream& operator<<(ostream& os, Omanip& m)
               { return m.f(os,m.i); }
        };

   Omanip_int ࠭ ᢮ 㬥  i  f,   
  operator<< 뢠 f()  ࠬ஬ i.  ꥪ ⠪ ᮢ
  뢠 ꥪ-㭪. ⮡ १ ப

           cout << setprecision(4) << angle

   ⠪,   ⥫, 室 ⮡ 饭  setprecision(4)
  ᮧ ﭭ ꥪ  Omanip_int, ᮤঠ騩 祭 4
   㪠⥫  㭪,  ⠭  ⮪ ostream 祭
  ६, 饩 筮 ⢥:

       ostream& _set_precision(ostream&,int);

       Omanip_int setprecision(int i)
       {
           return Omanip_int(&_set_precision,i);
       }

  뢠 ᤥ ।, operator<<() ਢ  맮
  precision(i).
          ⮬⥫쭮 ।   Omanip_int  
  ⨯ 㬥⮢, ⮬  । 蠡 ⨯:

       template<class T> class OMANIP {
           T i;
           ostream& (*f) (ostream&,T);
       public:
           OMANIP(ostream (*ff) (ostream&,T), T ii)
               : f(ff), i(ii) { }

       friend ostream& operator<<(ostream& os, OMANIP& m)
           { return m.f(os,m.i) }
       };

    OMANIP ਬ  ⠭ 筮  ᮪ ⠪:

       ostream& precision(ostream& os,int)
       {
           os.precision(i);
           return os;
       }

       OMANIP<int> setprecision(int i)
       {
           return OMANIP<int>(&precision,i);
       }

   䠩  <iomanip.h>    蠡 ⨯ OMANIP,    
  istream - 蠡 ⨯ SMANIP,  SMANIP -   ioss.
    ⠭ ஢,  । 筮
  ⥪, ᠭ . ⬥⨬, ணࠬ  । 
  室  ,  ࠣ । istream,
  ostream, OMANIP  SMANIP.
          ஢ । . .  孮 楤
  ࠧ⪨ (layout ) ⥬ -뢮 68.  孨 
    ਫ  -뢮.    ⮬, 
  ᮧ ꥪ,   । 㤠 㣮  
  ᯮ  㭪. । ꥪ   
  襭, ᪮ ⠫ 믮 筮 । ᮧ⥫
  ꥪ,  筮 ⥬,    頥.

  10.4.2.1 ⠭  -뢮

   ᫥騥 :

       // Simple manipulators:
       ios& oct(ios&);  //  쬥筮 
       ios& dec(ios&);  //  筮 
       ios& hex(ios&);  //  ⭠筮 
       ostream& endl(ostream&);   //  '\n'  뢥
       ostream& ends(ostream&);   //  '\0'  뢥
       ostream& flush(ostream&);  // 뤠 ⮪

       istream& ws(istream&);     // 㤠 饭 ஡

       //   ࠬ:

       SMANIP<int>  setbase(int b);
       SMANIP<int>  setfill(int f);
       SMANIP<int>  setprecision(int p);
       SMANIP<int>  setw(int w);
       SMANIP<long> resetiosflags(long b);
       SMANIP<long> setiosflags(long b);

  ਬ,

         cout << 1234 << ' '
              << hex  << 1234 << ' '
              << oct  << 1234 << endl;

  ⠥

         1234 4d2 2322

  

         cout << setw(4) << setfill('#') << '(' << 12 << ")\n";
         cout << '(' << 12 << ")\n";

  ⠥

         (##12)
         (12)

     䠩 <iomanip.h>, ᫨ ᯮ  
  ࠬࠬ.

  10.4.3  ostream

    ostream   ᪮쪮 㭪権  ࠢ 뢮,
    ⠪ 㭪権 室   ios.

       class ostream : public virtual ios {
           //...
       public:
           ostream& flush();

           ostream&  seekp(streampos);
           ostream&  seekp(streamoff, seek_dir);
           streampos tellp();
           //...
       };

    㦥 ਫ, 㭪 flush() 蠥   室 ⮪.
  ⠫ 㭪樨 ᯮ  樮஢  ostream 
  . 砭  㪢 p 㪠뢠,    ᯮ
   뤠 ᨬ   ⮪. 筮  㭪樨  ,
  ⮫쪮 ᫨ ⮪ ᮥ  祬-,  ᪠
  樮஢, ਬ 䠩.  streampos ।⠢  ᨬ
   䠩,  ⨯ streamoff ।⠢ ᬥ饭 ⭮⥫쭮 樨,
   seek_dir.   ।   ios:

       class ios {
           //...
           enum seek_dir {
              beg=0,  //  砫 䠩
              cur=1,  //  ⥪饩 樨  䠩
              end=2   //   䠩
           };
           //...
       };

  樨  ⮪ 뢠  0,  ᫨  䠩  ᨢ 
  n ᨬ:

           char file[n-1];

   ᫨ fout ᮥ  file, 

           fout.seek(10);
           fout<<'#';

   #  file[10].

  10.4.4  istream

     ostream, 設⢮ 㭪権 ଠ஢  ࠢ
   室    iostream,     ios.

       class istream : public virtual ios {
           //...
       public:
           int         peek()
           istream&    putback(char c);

           istream&    seekg(streampos);
           istream&    seekg(streamoff, seek_dir);
           streampos   tellg();
           //...
       };

  㭪樨 樮஢ ࠡ      ostream.
  砭  㪢 g 뢠,    ᯮ 
   ᨬ   ⮪. 㪢 p  g 㦭, ᪮
    ᮧ ந  iostreams  ᮢ ostream 
  istream,    室 ᫥  ﬨ   뢮.
        㭪樨 peek() ணࠬ  㧭 ᫥騩 ᨬ,
  騩 ,  ࠣ १ ᫥饣 ⥭. 
   㭪樨 putback(),    $$10.3.3,  
  㦭 ᨬ   ⮪, ⮡   ⠭  㣮 ६.

  10.5   ⮪

   ਢ ணࠬ ஢  䠩  㣮. 
  䠩    ப ணࠬ:

       #include <fstream.h>
       #include <libc.h>

       void error(char* s, char* s2 ="")
       {
          cerr << s << ' ' << s2 << '\n';
          exit(1);
       }

       int main(int argc, char* argv[])
       {
           if (argc != 3) error("wrong number of arguments");

           ifstream from(argv[1]);
           if (!from) error("cannot open input file",argv[1]);

           ostream to(argv[2]);
           if (!to) error("cannot open output file",argv[2]);

           char ch;
           while (from.get(ch)) to.put(ch);

           if (!from.eof() || to.bad())
              error("something strange happened");

           return 0;
        }

    室 䠩 ᮧ ꥪ  ofstream -
  室 ⮪ 䠩, ᯮ騩  ⢥ 㬥  䠩.
  筮,   室 䠩 ᮧ ꥪ 
  ifstream - 室 䠩 ⮪, ⠪ ᯮ騩  ⢥
  㬥  䠩.    ᫥  ஢ ﭨ
  ᮧ ꥪ, ⮡ 㡥  ᯥ譮 ⨨ 䠩, 
  ᫨   ⠪, 樨   ᯥ譮,  ४⭮.
         㬮砭 ifstream ᥣ 뢠  ⥭,  ofstream
  뢠  .  ostream   istream  ᯮ짮
  易⥫ ன 㬥, 㪠뢠騩  ० :

       class ios {
       public:
           //...
           enum open_mode {
              in=1,            //   ⥭
              out=2,           //   室
              ate=4,           //   ६   䠩
              app=010,         // 
              trunc=020,       // ᮪ 䠩  㫥 
              nocreate=040,    // 㤠, ᫨ 䠩  
              noreplace=0100   // 㤠, ᫨ 䠩 
           };
           //...
       };

  騥 祭  open_mode    ⭮  
   ॠ樨.  ,  ⠫ﬨ   㪮 
  襩 ⥪  ᯥਬ. ਢ ਨ
   ᭨  祭. ਬ,   䠩  ᫮,
      믮, ᫨ 䠩 㦥  :

       void f()
       {
           ofstream mystream(name,ios::out|ios::nocreate);

           if (ofstream.bad()) {
               //...
           }
           //...
       }

     䠩 ࠧ  ⥭  :

         fstream dictionary("concordance", ios::in|ios::out);

   樨, ⨬  ostream  ostream,  ਬ 
  fstream.  ᠬ ,  fstream  ந  iostream,
   ,  ᢮ ।, ந  istream  ostream.
  稭,  ன ଠ  ਧ樨  ଠ஢ 
  ostream  istream 室  㠫쭮   ios,  ⮬,
  ⮡ ⠢ ⢮   ᫥⥫쭮 ந
  ᮢ.  ⮩  稭 樨 樮஢  istream 
  ostream  ࠧ  - seekp()  seekg().  iostream 
  ⤥ 樨  ⥭  .

  10.5.1 ⨥ ⮪

      , ᫨ 맢 close()   ⮪:

        mystream.close();

       ⮪, ⠪   맮 close()
   , ᫨ ⮫쪮 䠩 㦭   ⨦
    । ⮪.
          ,  ॠ  ᯥ
  ᮧ ।। ⮪ cout, cin  cerr   ࢮ
  ᯮ짮  ⨥  ⮫쪮 ᫥ ᫥ ᯮ짮.
  筮, ࠧ ॠ樨 ⥪ ⮪  <iostream.h> 
  -ࠧ   .   殢, 襭 - 
  ண⨢ ॠ樨,       짮⥫. 
  ਢ ⮫쪮  ᯮᮡ, ਬ ⮫쪮   ॠ樨,
    筮 騩, ⮡ ࠭஢ ࠢ 冷
  ᮧ  㭨⮦  ꥪ⮢ ࠧ ⨯.
        ᭮   ⮬, ⮡ । ᯮ⥫ ,
     㦨 稪, ᫥騬  ⥬, ᪮쪮 ࠧ
  <iostream.h>  祭  ࠧ쭮 ஢訥 ணࠬ
  䠩:

       class Io_init {
           static int count;
           //...
       public:
           Io_init();
           ^Io_init();
       };

       static Io_init io_init ;

    ணࠬ 䠩 । ᢮ ꥪ   io_init.
    ꥪ⮢ io_init ᯮ Io_init::count  
  ਧ ⮣,  ⢨⥫쭠 樠  ꥪ⮢
  ⮪ ⥪ -뢮 ᤥ  筮  ࠧ:

       Io_init::Io_init()
       {
          if (count++ == 0) {
              // 樠஢ cout
              // 樠஢ cerr
              // 樠஢ cin
              //  ..
          }
       }

  ⭮,   ꥪ⮢ io_init ᯮ Io_count, 
  ᫥ 㪠  ,   ⮪ :

       Io_init::^Io_init()
       {
          if (--count == 0) {
              //  cout (,  ..)
              //  cerr (,  ..)
              //  cin
              //  ..
          }
        }

   騩 ਥ ࠡ  ⥪, ॡ騬 樠樨 
  㤠  ꥪ⮢.   ++  ਬ . .
   ⥬,   믮  ணࠬ ࠧ  ᭮
  ,  ⮣ ਥ  . ᫨   ⠪,  
  室, 易  맮    ணࠬ 䠩
   믮 㭪権 樠樨,  .  ᥣ,
  ,  ,   ꥪ⮢.  ᮢ,
      ⥫쭠  ꥬ 믮塞 ࠡ,
  ⮡ ࠭஢ 樠, 뫮  ࠧ㬭 ஢ ⠪
   ਧ ( Io_init::count)   樨.
  ,  ⮪ ⠪ 室   譥 ⥫.

  10.5.2 ப ⮪

   뫮 , ⮪   ਢ易  䠩, .. ᨢ
  ᨬ, ࠭饬   ᭮ , , ਬ,  ᪥. 筮
  ⠪  ⮪  ਢ易  ᨢ ᨬ  ᭮ .
  ਬ,  ᯮ짮 室 ப ⮪ ostrstream
   ଠ஢ ᮮ饭,    :

       char* p = new char[message_size];
       ostrstream ost(p,message_size);
       do_something(arguments,ost);
       display(p);

    ⠭ 権 뢮 㭪 do_something  
   ⮪ ost, । ost 稭騬  㭪  .. ஫
  ९  㦥, ᪮ ost  ᢮ ࠧ   
  ३  ﭨ, ।塞 fail(). ⥬ 㭪 display 
  ᫠ ᮮ饭  "騩" 室 ⮪.  ਥ 
  室   ,  ⥫쭠  뢮
  ।祭     ᫮ ன⢮, 祬 ࠤ樮,
  ਥ஢  ᫥⥫쭮 ப, 뢮 ன⢮.
  ਬ, ⥪  ost   饭  䨪஢   ࠭.
          筮, istrstream   ப ⮪,
  騬  ᫥⥫쭮 ᨬ, 稢饩 㫥:

       void word_per_line(char v[], int sz)
       /*
           "v" ࠧ஬ "sz"   ᫮  ப
       */
       {
          istrstream ist(v,sz);  // ᮧ istream  v
          char b2[MAX];          //  ᠬ  ᫮
          while (ist>>b2) cout <<b2 << "\n";
        }

  騩  ⠥ 殬 䠩.
          ப ⮪ ᠭ  䠩 <strstream.h>.

  10.5.3 ਧ

   樨 -뢮 뫨 ।  类 裡  ⨯
  䠩,    ࠡ  ᥬ ன⢠  
  ⬠ ਧ樨. 祢,  ⮪ ostream, ਢ易 
  ப ᨬ, 㦥  ⠪ ,  ostream, ਢ易 
  䠩.    ᮧ  ६ 樠樨 ࠧ
  ஢  ⮪ ࠧ ⨯.   ⮫쪮  
  権  ⨬ ⨯ ஢, ⮬  ostream  㭪権, 
   뢠 ࠧ稥 ஢. , 㭪樨, ᫥騥 
  ९  饭  ⮬ ,  㠫묨.
   訩 ਬ ਬ 㠫 㭪権  ࠧ
  ࠡ  묨 ᪨,  ࠧ筮 ॠ묨
  ࠬ,    ࠢ  ॡ㥬묨 ⬠ ਧ樨.
  ᠭ  ⮪  䠩 <iostream.h>  룫拉 ᫥騬
  ࠧ:

       class streambuf {     // ࠢ ஬ ⮪
       protected:
           char* base;       // 砫 
           char* pptr;       // ᫥騩 ᢮ 
           char* gptr;       // ᫥騩  
           char* eptr;       //   㪠⥫   
           char  alloc;      // , ࠧ饭   "new"
           //...
           //  :
           //  EOF  訡, 0 - 㤠
       virtual int overflow(int c = EOF);

           //  :
           //  EOF  砥 訡   室 ⮪,
           //   । ᨬ
        virtual int underflow();
        //...
        public:
            streambuf();
            streambuf(char* p, int l);
            virtual ~streambuf();

            int snextc()       //  । ᨬ
            {
                return (++gptr==pptr) ? underflow() : *gptr&0377;
            }
            int allocate();    // ⢥   
            //...
       };

  ஡ ॠ樨  streambuf ਢ  ⮫쪮 
   ।⠢.  ।,   饤㯭
  ॠ樨, ᯮ騥   .   
  ।  㪠⥫, ࠢ騥 ஬;   
   ᨬ 樨  ⮪  । ᨬ쭮
  䥪⨢ ( 祬 ⭮)  㭪樨-⠭. 쪮
  㭪樨 overflow()  underflow() ॡ ᢮ ॠ樨  
  ⬠ ਧ樨, ਬ:

       class filebuf : public streambuf {
       protected:
           int  fd;            // ਯ 䠩
           char opened;        // ਧ  䠩
       public:
           filebuf() { opened = 0; }
           filebuf(int nfd, char* p, int l)
               : streambuf(p,l) { /* ... */ }
           ~filebuf() { close(); }

           int overflow(int c=EOF);
           int underflow();

           filebuf* open(char *name, ios::open_mode om);
           int close() { /* ... */ }
           //...
       };
       int filebuf::underflow()    //    "fd"
       {
           if (!opened || allocate()==EOF) return EOF;

           int count = read(fd, base, eptr-base);
           if (count < 1) return EOF;

           gptr = base;
           pptr = base + count;
           return *gptr & 0377; // &0377 ।頥 ࠧ 
        }

   쭥訬 ஡ﬨ   㪮  ॠ樨
   streambuf.

  10.6 -뢮  

  ᪮ ⥪ ணࠬ     ++  ,   
   ⮪ -뢮 ++  㭪樨 -뢮 ᥬ⢠  printf 
  몠 . , .. -㭪樨  뢠  ணࠬ  ++, 
   । ᯮ짮   㭪樨 -뢮 .
           ⮩ 稭  㤥  ᭮ 㭪権 -뢮 .
  筮 樨 -뢮     ++    । 
  ஢ ப. ६訢   ஢ ᨬ쭮 -뢮
     ॠ権,  ⠪ ணࠬ  
  ७ᨬ.  ॠ樨 ⮪ ⥪ ++  饭
  -뢮   ॡ 맮 ᪮ 㭪樨-童
  ios::sync_with_stdio().
            饬, ⮪ 㭪樨 뢮  । ⠭⭮
  㭪樥  printf()  २⢮,  ⮪ 㭪樨 
  । ⨯   ࠧ । 뢮
  ꥪ⮢ ।।  짮⥫᪮ ⨯.
       ᭮ 㭪 뢮  

          int printf(const char* format, ...)

    뢮 ந ᫥⥫쭮 ࠬ஢  ଠ,
   ப ଠ஢ format. ப ଠ஢ ⮨
   ꥪ⮢  ⨯:  ᨬ,    
  室 ⮪,  ᯥ䨪樨 ८ࠧ,   
  ८ࠧ  ⠥ । ࠬ.   ᯥ䨪
  ८ࠧ 稭  ᨬ %, ਬ

          printf("there were %d members present.",no_of_members);

   %d 㪠뢠,  no_of_members ᫥  楫  
   ᮮ⢥ ᫥⥫쭮  . ᫨
  no_of_members==127,  㤥 ⠭

         there were 127 members present.

       ᯥ䨪権 ८ࠧ 筮 让  ᯥ稢
    .  ᨬ %  ᫥:
  - 易⥫  , 騩 ࠢ   㪠
      ८ࠧ 祭;
  d 易⥫쭠 ப ,   ਭ ; ᫨ 
    ८ࠧ 祭  ᨬ, 祬 ਭ ப,  
      ਭ  ஡ ᫥ ( ࠢ, ᫨ 
    ᯥ䨪 ࠢ ); ᫨ ப ਭ  稭
     ,   㤥 ஢ ﬨ,   ஡;
  . 易⥫ ᨬ 窠 㦨  ⤥ ਭ  
    ᫥饩 ப ;
  d 易⥫쭠 ப ,  筮,  ।
    ᫮  ᫥ 筮 窨  祭  ᯥ䨪
    e  f,    ᨬ쭮 ᫮ ⠥ ᨬ
    ப;
  *   ਭ   筮  ᯮ짮 * 
    ப .  ⮬ 砥   ࠬ 楫 ⨯, 
    ᮤন 祭 ਭ   筮;
  h 易⥫ ᨬ h 㪠뢠,  ᫥ ᯥ䨪 d,
    o, x  u ⭮  ࠬ ⨯ ⪮ 楫;
  l 易⥫ ᨬ l 㪠뢠,  ᫥ ᯥ䨪 d,
    o, x  u ⭮  ࠬ ⨯  楫;
  % 砥,  㦭  ᠬ ᨬ %; ࠬ  㦥;
  c ᨬ, 㪠뢠騩 ⨯ ॡ㥬 ८ࠧ. 
    ८ࠧ    ᫥騥:
        d  ࠬ 뤠  筮 ;
        o  ࠬ 뤠  쬥筮 ;
        x  ࠬ 뤠  ⭠筮 ;
        f ⢥    筮 ࠬ 뤠 
          筮    [-]ddd.ddd,  ᫮  ᫥
          窨 ࠢ ᯥ䨪樨 筮  ࠬ. ᫨ 筮
           , ⠥  ; ᫨   筮 0,
          窠   ᫥   ;
        e ⢥    筮 ࠬ 뤠 
          筮   [-]d.ddde+dd;    ।
          窮,  ᫮  ᫥ 窨 ࠢ ᯥ䨪樨 筮
           ࠬ; ᫨    ⠥  ;
        g ⢥    筮 ࠬ ⠥  ⮩
          ᯥ䨪樨 d, f  e,    筮 
          襩 ਭ ;
        c  ࠬ ⠥. 㫥 ᨬ ;
        s ࠬ ⠥ ப (ᨬ 㪠⥫),  
          ᨬ  ப  㫥 ᨬ   ⨦ ᫠
          ᨬ, ࠢ ᯥ䨪樨 筮; , ᫨ 筮
          ࠢ 0   㪠,   ᨬ  㫥;
        p ࠬ ⠥ 㪠⥫       
          ॠ樨;
        u  楫 ࠬ ⠥  筮 .
  饥     ਭ, 襩 ॠ쭮, ਢ
   祭 .  ஡ ந室, ᫨ ⮫쪮
  ᯥ䨪 ਭ   ॠ쭮 ਭ.
   ਢ  ᫮ ਬ:

       char* src_file_name;
       int line;
       char* line_format = "\n#line %d \"%s\"\n";
       main()
       {
          line = 13;
          src_file_name = "C++/main.c";

          printf("int a;\n");
          printf(line_format,line,src_file_name);
          printf("int b;\n");
       }

   ஬ ⠥

        int a;

        #line 13 "C++/main.c"
        int b;

        ᯮ짮 printf()   ⮬ ᫥,   
  ஫ ⨯. ,  ਢ  ᯮᮡ 祭
   १ -  ୮ 祭  祣 㦥:

        char x;
        // ...
        printf("bad input char: %s",x);

  ,  㭪樨 ᯥ稢    
  ணࠬ騬  .
         筮, getchar()   ᯮᮡ  ᨬ 
  室 ⮪:

        int i;:
        while ((i=getchar())!=EOF) { // ᨬ  C
           // ᯮ㥬 i
        }

   : ⮡ 뫮  ࠢ  稭 EOF ⨯
  int  ஢થ   䠩, १ getchar()   
  ६ ⨯ int,   char.
       ஡ﬨ  -뢮   뫠  襬 㪮
      ୨   " ணࠬ஢ ".

  10.7 ࠦ

  1. (*1.5)  䠩 ⢥ ᥫ, ⠢   ⠭
     ᥫ  ᫠,   ᫠.
  2. (*1.5) । ⨯ name_and_address (⨯__). । 
      <<  >>.  ணࠬ ஢ ꥪ⮢ ⮪
     name_and_address.
  3. (*2) ࠡ ᪮쪮 㭪権    ⥭ 
     ࠧ ⨯. ।: 楫, ⢥ ᫮,  䠩,
     ⮢ , , 筠 ଠ,  .. ⠩ ᤥ
      ⮩稢묨  訡.
  4. (*1.5)  ணࠬ,  ⠥: (1)  㪢,
     (2)  㪢, (3)  㪢  , (4)  ᨬ, 室騥 
     䨪  襩 ᨨ ++, (5)   㭪樨,
     (6) 楫 祭  ࠢ ᨬ, (7)  饭
     ஡, (8) 楫 祭  饭 ஡, , ,
     (9)  ࠦ ᨬ.
  5. (*4)  ⠭ ⥪ -뢮  (<stdio.h>)
       ⠭⭮ ⥪ -뢮 ++ (<iostream.h>).
  6. (*4)  ⠭ ⥪ -뢮 ++
     (<iostream.h>)   ⠭⭮ ⥪ -뢮 
     (<stdio.h>).
  7. (*4)  ⥪   ++ ⠪, ⮡   뫮
     ᯮ짮 ६.
  8. (*2)  ,  ண  [] ॣ㦥 ⠪,
     ⮡ ᯥ ந쭮 ⥭ ᨬ  䠩.
  9. (*3)  ࠦ 8,  , ⮡  [] 뫠
     ਬ  ⥭   . ᪠:  [] 頥
     ꥪ "ਯ ⨯",  ண ᢠ 砥:
     ᢮ १ ਯ 䠩,   ਢ  ⨯ char
     砥 ⥭ 䠩  ਯ.
  10.(*2)  ࠦ 9,  樨 [] ஢
     ꥪ ந ⨯,   ⮫쪮 ᨬ.
  11.(*3.5) த㬠   ॠ  ଠ⭮ .
     ᯮ   ଠ ப ᯥ䨪権   printf().
         ⮪ ਬ ᪮쪨 ᯥ䨪権 
      , ⮡  ॡ㥬 ଠ.  ଠ⭮ 
       ந  istream.
  12.(*4) ਤ㬠 ( ॠ) 訥 ଠ .
  13.(**2) ।  뢮  based   ࠬࠬ:
     ⥬ ᫥  楫 祭,  ⠩ 楫 
     ।⠢, ।塞 ⥬ ᫥. ਬ, based(2,9)
     ⠥ 1001.
  14.(**2)  "" ⥬ -뢮,  ॠ
      istream, ostream, ifstream, ofstream  ।⠢ 㭪樨,
     ⠪  operator<<()  operator>>()  楫,  樨, ⠪
      open()  close()  䠩. ᯮ ᪫⥫
     樨,   ६ ﭨ,  ᮮ饭  訡.
  15.(**2)  ,  砥  ⪫砥 
     ᨬ.

