home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / os / os2 / programm / 6335 < prev    next >
Encoding:
Internet Message Format  |  1992-11-11  |  1.5 KB

  1. Path: sparky!uunet!airgun!airgun.wg.waii.com!bab
  2. From: bab@se39.wg2.waii.com (Brian Button)
  3. Newsgroups: comp.os.os2.programmer
  4. Subject: Possible bug in GCC/2 iostreams???
  5. Message-ID: <BAB.92Nov11072433@se39.wg2.waii.com>
  6. Date: 11 Nov 92 12:24:33 GMT
  7. Sender: news@airgun.wg.waii.com
  8. Organization: Western Geophysical Exploration Products
  9. Lines: 42
  10. Nntp-Posting-Host: se39.wg2.waii.com
  11.  
  12. I seem to be having a problem reading in the contents of a file using
  13. iostreams. When I use any multi-char read methods, I get the first
  14. byte twice. For example :
  15.  
  16. {
  17.     ifstream ifs( "test.data" );
  18.     char buf[ 16 ];
  19.     ifs.read( buf, 16 );
  20. }
  21.  
  22. If the contents of test.data are "abcdefghijklmnop", I'll read
  23. "aabcdefghijklmno".
  24.  
  25. If I change the reading code to
  26.  
  27.     ifs.rdbuf( )->sgetn( buf, 16 );
  28.  
  29. I get the same results.
  30.  
  31. However, if I change to
  32.  
  33.     for( i = 0; i < 16; i++ )
  34.     {
  35.         int ch = ifs.rdbuf( )->sgetc( );
  36.     }
  37.  
  38. everything works fine for me.
  39.  
  40. Am I doing something wrong here or is this a bug in GCC/2?
  41.  
  42. thanks,
  43.  
  44. bab
  45.  
  46. --
  47. |-----------------------|----------------------------------------------------|
  48. | Brian Button          | email : button@wg2.waii.com                        |
  49. | Design Engineer       |         71023.276@compuserve.com                   |
  50. | Western Geophysical   | voice : (713)964-6221                              |
  51. | 3600 Briarpark        |----------------------------------------------------|
  52. | Houston, Texas  77042 |                  Opinions Be Mine!!                |
  53. |-----------------------|----------------------------------------------------|
  54.