home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!europa.asd.contel.com!howland.reston.ans.net!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!not-for-mail
- From: ren@miles.mps.ohio-state.edu (Liming Ren)
- Newsgroups: comp.lang.c++
- Subject: Questions about iostream. Please help!
- Date: 18 Dec 1992 14:33:02 -0500
- Organization: Department of Mathematics, The Ohio State University
- Lines: 46
- Distribution: world
- Message-ID: <1gt91eINNfrf@miles.mps.ohio-state.edu>
- NNTP-Posting-Host: miles.mps.ohio-state.edu
-
- The following program was posted in this group (not by me) a while ago.
-
- #include <iostream.h>
- #include <strstream.h>
- #include <fstream.h>
- int main( int argc, char ** argv )
- {
- istream * is;
- if( argc == 2 ){
- is = new ifstream( argv[ 1 ] );
- }else{
- is = &cin;
- }
- while( *is ){
- ostrstream out_str;
- is->get( *out_str.rdbuf( ));
- is->ignore( 1, '\n' );
- cout <<out_str.rdbuf( )<< endl;
- }
-
- if( argc == 2 ){ // Delete the object created.
- delete is;
- }
- return 0;
- }
-
-
- After I study it, I have two questions:
-
- (1) If I use it as : a.out file1>file2, diff tells me there is an extra newline added to file2
- at the end of file. I don't see how this can happen. How to correct it?
-
- (1) About the main while loop. It is my understanding that *is is a class instance of
- istream with the following picyure:
-
- ______ _____________________
- | is |---------->| |
- ------ | |
- | istream |
- |___________________|
-
- How (*is) can be zero and how it is set to zero? Does this mean that the class instance is
- zero? I am comfused here.
-
-
- Many thanks!
-