home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / msdos / programm / 9125 < prev    next >
Encoding:
Text File  |  1992-09-08  |  1.4 KB  |  64 lines

  1. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!wupost!usc!snorkelwacker.mit.edu!ira.uka.de!datmuc!vincent
  2. From: vincent@datmuc.UUCP (vincent)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: C700 streams
  5. Message-ID: <1263@datmuc.UUCP>
  6. Date: 7 Sep 92 15:22:12 GMT
  7. Lines: 55
  8.  
  9.  
  10.  
  11. //////////////////////  cut here /////////////////////////////////
  12.  
  13. #include    <fstream.h>
  14. #include    <iomanip.h>
  15.  
  16. main (int argc, char **argv)
  17. {
  18.     fstream ci;
  19.     char s [3];
  20.  
  21.     ci. open (argv [1], ios::in | ios::binary);
  22.     ci. unsetf (ios::skipws);
  23.  
  24.     s [1] = '_';
  25.     s [2] = '\0';
  26.  
  27.     while (ci. good ()) {
  28.         ci >> s [0];
  29.         if (ci. eof ())
  30.             break;
  31.         cout << s;
  32.     }
  33. }
  34.  
  35. //////////////////////  cut here /////////////////////////////////
  36.  
  37.  
  38. Looks benign, well it is. BUT I've got a problem with it.
  39.  
  40. My input file contains "Hello World!"
  41.  
  42. My output is:
  43.  
  44. __e_l_l_o _W_o_r_l_d_!_
  45. _
  46.  
  47.  
  48. If I remove ios::binary from my open input file it works as expected.
  49.  
  50. A N Y   I D E A S   ? ? ?
  51.  
  52. P.S. Of course I played with this piece of code for a while and found
  53. some solutions (i.e. replace the string whith a char) but I would
  54. like to know more about this. I've also used CodeView but it didn't
  55. help me. I know now that the string is correctly passed to the cout
  56. manipulator. And that it affect only the first charater of that string
  57. funy it looks like the second char ('_') is duplicated in the first
  58. position; ?????
  59.  
  60.              }8-[] 
  61.  
  62. vincent@datmuc.dat.de
  63.  
  64.