home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13167 < prev    next >
Encoding:
Internet Message Format  |  1992-09-01  |  1.4 KB

  1. Path: sparky!uunet!sun-barr!ames!agate!forney.berkeley.edu!jbuck
  2. From: jbuck@forney.berkeley.edu (Joe Buck)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: istrstream
  5. Date: 2 Sep 1992 01:13:43 GMT
  6. Organization: U. C. Berkeley
  7. Lines: 23
  8. Message-ID: <1814g7INNr59@agate.berkeley.edu>
  9. References: <1992Sep1.225259.1533@Warren.MENTORG.COM>
  10. NNTP-Posting-Host: forney.berkeley.edu
  11.  
  12. In article <1992Sep1.225259.1533@Warren.MENTORG.COM> adk@Warren.MENTORG.COM (Ajay Kamdar) writes:
  13. >Why do istrstream constructors take a char* instead of a const char* ?
  14. >This either stops me from reading a formatted input string (which I get
  15. >as a const char*) as an istrstream, or compels me to cast away the const
  16. >on the string when constructing the istrstream.
  17.  
  18. This annoys me too.  The reason appears to be that istrstream and
  19. ostrstream are both derived from strstream, and it is the strstream
  20. constructor that requires the "char *" argument.  Still, it would be nice
  21. if this could be avoided.  I despise casting away const, and currently
  22. this is the only place where I feel compelled to do it.  It still may 
  23. not be safe, because of putback.
  24.  
  25. Depending on the implementation, I suppose that it is possible that
  26. istream::putback(char) might modify the argument to the istrstream
  27. constructor, which could cause trouble if you passed a string argument
  28. and the code modified the string (possibly causing a bus error if the
  29. string is in ROM).
  30.  
  31.  
  32.  
  33. --
  34. Joe Buck    jbuck@ohm.berkeley.edu
  35.