home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / libg++-2.6-fsf.lha / libg++-2.6 / libio / iostream.info-2 (.txt) < prev    next >
GNU Info File  |  1994-07-18  |  14KB  |  288 lines

  1. This is Info file iostream.info, produced by Makeinfo-1.55 from the
  2. input file ./iostream.texi.
  3. START-INFO-DIR-ENTRY
  4. * iostream: (iostream).                    The C++ input/output facility.
  5. END-INFO-DIR-ENTRY
  6.    This file describes libio, the GNU library for C++ iostreams and C
  7. stdio.
  8.    libio includes software developed by the University of California,
  9. Berkeley.
  10.    Copyright (C) 1993 Free Software Foundation, Inc.
  11.    Permission is granted to make and distribute verbatim copies of this
  12. manual provided the copyright notice and this permission notice are
  13. preserved on all copies.
  14.    Permission is granted to copy and distribute modified versions of
  15. this manual under the conditions for verbatim copying, provided also
  16. that the entire resulting derived work is distributed under the terms
  17. of a permission notice identical to this one.
  18.    Permission is granted to copy and distribute translations of this
  19. manual into another language, under the above conditions for modified
  20. versions.
  21. File: iostream.info,  Node: Backing Up,  Next: Indirectbuf,  Prev: Procbuf,  Up: Streambuf
  22. Backing up
  23. ==========
  24.    The GNU iostream library allows you to ask a `streambuf' to remember
  25. the current position.  This allows you to go back to this position
  26. later, after reading further.  You can back up arbitrary amounts, even
  27. on unbuffered files or multiple buffers' worth, as long as you tell the
  28. library in advance.  This unbounded backup is very useful for scanning
  29. and parsing applications.  This example shows a typical scenario:
  30.      // Read either "dog", "hound", or "hounddog".
  31.      // If "dog" is found, return 1.
  32.      // If "hound" is found, return 2.
  33.      // If "hounddog" is found, return 3.
  34.      // If none of these are found, return -1.
  35.      int my_scan(streambuf* sb)
  36.      {
  37.          streammarker fence(sb);
  38.          char buffer[20];
  39.          // Try reading "hounddog":
  40.          if (sb->sgetn(buffer, 8) == 8
  41.              && strncmp(buffer, "hounddog", 8) == 0)
  42.            return 3;
  43.          // No, no "hounddog":  Back up to 'fence'
  44.          sb->seekmark(fence); //
  45.          // ... and try reading "dog":
  46.          if (sb->sgetn(buffer, 3) == 3
  47.              && strncmp(buffer, "dog", 3) == 0)
  48.            return 1;
  49.          // No, no "dog" either:  Back up to 'fence'
  50.          sb->seekmark(fence); //
  51.          // ... and try reading "hound":
  52.          if (sb->sgetn(buffer, 5) == 5
  53.              && strncmp(buffer, "hound", 5) == 0)
  54.            return 2;
  55.          // No, no "hound" either:  Back up and signal failure.
  56.          sb->seekmark(fence); // Backup to 'fence'
  57.          return -1;
  58.      }
  59.  - Constructor:  streammarker::streammarker (streambuf* SBUF)
  60.      Create a `streammarker' associated with SBUF that remembers the
  61.      current position of the get pointer.
  62.  - Method: int streammarker::delta (streammarker& MARK2)
  63.      Return the difference between the get positions corresponding to
  64.      `*this' and MARK2 (which must point into the same `streambuffer'
  65.      as `this').
  66.  - Method: int streammarker::delta ()
  67.      Return the position relative to the streambuffer's current get
  68.      position.
  69.  - Method: int streambuffer::seekmark (streammarker& MARK)
  70.      Move the get pointer to where it (logically) was when MARK was
  71.      constructed.
  72. File: iostream.info,  Node: Indirectbuf,  Prev: Backing Up,  Up: Streambuf
  73. Forwarding I/O activity
  74. =======================
  75.    An "indirectbuf" is one that forwards all of its I/O requests to
  76. another streambuf.
  77.    An `indirectbuf' can be used to implement Common Lisp
  78. synonym-streams and two-way-streams:
  79.      class synonymbuf : public indirectbuf {
  80.         Symbol *sym;
  81.         synonymbuf(Symbol *s) { sym = s; }
  82.         virtual streambuf *lookup_stream(int mode) {
  83.             return coerce_to_streambuf(lookup_value(sym)); }
  84.      };
  85. File: iostream.info,  Node: Stdio,  Next: Index,  Prev: Streambuf,  Up: Top
  86. C Input and Output
  87. ******************
  88.    `libio' is distributed with a complete implementation of the ANSI C
  89. `stdio' facility.  It is implemented using `streambuf' objects.  *Note
  90. Wrappers for C `stdio': Stdiobuf.
  91.    The `stdio' package is intended as a replacement for the whatever
  92. `stdio' is in your C library.  Since `stdio' works best when you build
  93. `libc' to contain it, and that may be inconvenient, it is not installed
  94. by default.
  95.    Extensions beyond ANSI:
  96.    * A stdio `FILE' is identical to a streambuf.  Hence there is no
  97.      need to worry about synchronizing C and C++ input/output--they are
  98.      by definition always synchronized.
  99.    * If you create a new streambuf sub-class (in C++), you can use it
  100.      as a `FILE' from C.  Thus the system is extensible using the
  101.      standard `streambuf' protocol.
  102.    * You can arbitrarily mix reading and writing, without having to seek
  103.      in between.
  104.    * Unbounded `ungetc()' buffer.
  105. File: iostream.info,  Node: Index,  Prev: Stdio,  Up: Top
  106. Index
  107. *****
  108. * Menu:
  109. * (:                                    States.
  110. * (:                                    States.
  111. * << on ostream:                        Operators.
  112. * >> on istream:                        Operators.
  113. * iostream destructor:                  Iostream.
  114. * badbit:                               States.
  115. * beg:                                  Output Position.
  116. * cerr:                                 Operators.
  117. * cin:                                  Operators.
  118. * class fstreambase:                    Files.
  119. * class fstream:                        Files.
  120. * class ifstream:                       Files.
  121. * class istrstream:                     Strings.
  122. * class ostream:                        Files.
  123. * class ostrstream:                     Strings.
  124. * class strstreambase:                  Strings.
  125. * class strstreambuf:                   Strings.
  126. * class strstream:                      Strings.
  127. * cout:                                 Operators.
  128. * cur:                                  Output Position.
  129. * dec:                                  Manipulators.
  130. * destructor for iostream:              Iostream.
  131. * end:                                  Output Position.
  132. * endl:                                 Manipulators.
  133. * ends:                                 Manipulators.
  134. * eofbit:                               States.
  135. * failbit:                              States.
  136. * flush:                                Manipulators.
  137. * flush:                                Ostream Housekeeping.
  138. * fstream:                              Files.
  139. * fstreambase:                          Files.
  140. * fstreambase::close:                   Files.
  141. * get area:                             Areas.
  142. * goodbit:                              States.
  143. * hex:                                  Manipulators.
  144. * ifstream:                             Files.
  145. * ifstream:                             Files and Strings.
  146. * ifstream::ifstream:                   Files.
  147. * ifstream::ifstream:                   Files.
  148. * ifstream::ifstream:                   Files.
  149. * ifstream::open:                       Files.
  150. * ios::app:                             Files.
  151. * ios::ate:                             Files.
  152. * ios::bad:                             States.
  153. * ios::beg:                             Input Position.
  154. * ios::bin:                             Files.
  155. * ios::bitalloc:                        Extending.
  156. * ios::clear:                           States.
  157. * ios::cur:                             Input Position.
  158. * ios::dec:                             Format Control.
  159. * ios::end:                             Input Position.
  160. * ios::eof:                             States.
  161. * ios::fail:                            States.
  162. * ios::fill:                            Format Control.
  163. * ios::fill:                            Format Control.
  164. * ios::fixed:                           Format Control.
  165. * ios::flags:                           Format Control.
  166. * ios::flags:                           Format Control.
  167. * ios::good:                            States.
  168. * ios::hex:                             Format Control.
  169. * ios::in:                              Files.
  170. * ios::internal:                        Format Control.
  171. * ios::ios:                             Ios.
  172. * ios::iword:                           Extending.
  173. * ios::iword:                           Extending.
  174. * ios::left: