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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!stanford.edu!lucid.com!lucid.com!jss
  3. From: jss@lucid.com (Jerry Schwarz)
  4. Subject: Re: <stdio.h> and <iostream.h>
  5. Message-ID: <1992Sep2.180230.1427@lucid.com>
  6. Sender: usenet@lucid.com
  7. Reply-To: jss@lucid.com (Jerry Schwarz)
  8. Organization: Lucid, Inc.
  9. References:  <1SEP199214472267@cnsvax.uwec.edu>
  10. Date: Wed, 2 Sep 92 18:02:30 GMT
  11. Lines: 36
  12.  
  13. In article <1SEP199214472267@cnsvax.uwec.edu>, tannerrj@cnsvax.uwec.edu (Power = 486 + HST Dual Standard) writes:
  14. |> I am trying to put a text windowing environment on a C++ program
  15. |> that I have created. The text windowing environment is DFLAT from 
  16. |> DDJ magazine. The problem is DFLAT is ANSI C using stdio.h and
  17. |> my program is a C++ program with iostream.h. I have read that there
  18. |> are potential dangers in mixing the two. Any suggestions? Thanks.
  19. |> 
  20.  
  21. The problems with mixing stdio and iostream is one of syncronization.
  22. That is since stdio and iostream are each doing their own buffering
  23. it is possible that
  24.  
  25.     printf("stdio ") ;
  26.     cout << "iostream " ;
  27.  
  28. would end up with output
  29.  
  30.     iostream stdio
  31.  
  32. If you can arrange for flush to be called at appropriate points
  33. there is never any problem.  Some implementations
  34. of stdio will automatically flush when a newline is printed
  35. to certain output devices (this is called line buffering), and the 
  36. endl iostream manipulator also flushes.  
  37.  
  38. Alternatively you can call ios::sync_with_stdio before you do
  39. any other iostream operations.  This will cause cout and cerr
  40. to be connected to stdout and stderr which will allow for
  41. (almost) arbitrary mixing.
  42.  
  43. There is never any problem when stdio and iostreams are
  44. being used on different files.  
  45.  
  46.   -- Jerry Schwarz
  47.  
  48.  
  49.