home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18205 < prev    next >
Encoding:
Text File  |  1992-12-21  |  1.7 KB  |  58 lines

  1. Path: sparky!uunet!europa.asd.contel.com!howland.reston.ans.net!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!not-for-mail
  2. From: ren@miles.mps.ohio-state.edu (Liming Ren)
  3. Newsgroups: comp.lang.c++
  4. Subject: Questions about iostream. Please help!
  5. Date: 18 Dec 1992 14:33:02 -0500
  6. Organization: Department of Mathematics, The Ohio State University
  7. Lines: 46
  8. Distribution: world
  9. Message-ID: <1gt91eINNfrf@miles.mps.ohio-state.edu>
  10. NNTP-Posting-Host: miles.mps.ohio-state.edu
  11.  
  12. The following program was posted in this group (not by me) a while ago. 
  13.  
  14. #include    <iostream.h>
  15. #include    <strstream.h>
  16. #include    <fstream.h>
  17. int main( int argc, char ** argv )
  18. {
  19.     istream * is;
  20.     if( argc == 2 ){
  21.         is = new ifstream( argv[ 1 ] );
  22.     }else{
  23.         is = &cin;
  24.     }
  25.     while( *is ){
  26.         ostrstream out_str;
  27.         is->get( *out_str.rdbuf( ));
  28.         is->ignore( 1, '\n' );
  29.         cout <<out_str.rdbuf( )<< endl;
  30.     }
  31.  
  32.     if( argc == 2 ){    // Delete the object created. 
  33.         delete is;
  34.     }
  35.     return 0;
  36. }
  37.  
  38.  
  39. After I study it, I have two questions:
  40.  
  41. (1) If I use it as : a.out file1>file2, diff tells me there is an extra newline added to file2
  42. at the end of file. I don't see how this can happen. How to correct it?
  43.  
  44. (1) About the main while loop. It is my understanding that *is is a class instance of
  45. istream with the following picyure:
  46.  
  47.     ______             _____________________
  48.     | is |---------->|                   |
  49.     ------           |                   |
  50.                      | istream           |
  51.                      |___________________|
  52.  
  53. How (*is) can be zero and how it is set to zero? Does this mean that the class instance is 
  54. zero? I am comfused here.
  55.  
  56.  
  57. Many thanks!
  58.