home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13259 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1.1 KB  |  37 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: <stdio.h> and <iostream.h>
  5. Message-ID: <1992Sep3.170037.14131@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1SEP199214472267@cnsvax.uwec.edu> <1992Sep2.180230.1427@lucid.com>
  8. Date: Thu, 3 Sep 1992 17:00:37 GMT
  9. Lines: 26
  10.  
  11. jss@lucid.com (Jerry Schwarz) writes:
  12.  
  13. >The problems with mixing stdio and iostream is one of syncronization.
  14. >That is since stdio and iostream are each doing their own buffering ...
  15.  
  16. >If you can arrange for flush to be called at appropriate points
  17. >there is never any problem.
  18.  
  19. This is OK for output, but you will still have problems with input
  20. (which was not the original question).  For example, this code will
  21. produce bizarre results if input is from a file:
  22.  
  23.     int i, j;
  24.     while( ... ) {
  25.         cin >> i;
  26.         scanf("%d", &j);
  27.         ...
  28.     }
  29.  
  30. As Jerry and I both noted, you can call ios::sync_with_stdio() first
  31. to allow mixing.  It is probably best to avoid mixing stdio and
  32. iostream I/O on the same file.
  33. -- 
  34.  
  35. Steve Clamage, TauMetric Corp, steve@taumet.com
  36. Vice Chair, ANSI C++ Committee, X3J16
  37.