Topic: stringstreams and std::ios_base::openmode


Author: don_wakefield@mentor.com (Don Wakefield)
Date: Wed, 12 Sep 2007 16:41:43 GMT
Raw View
I can't seem to pull together the relevant pieces of the standard to
make sense of this. Any help and relevant pointers into the standard
would be appreciated. Thanks.

I can understand why basic_stringbuf's constructor takes an openmode
argument as it serves basic_istringstream, basic_ostringstream and
basic_stringstream. But why do the stringstreams themselves take an
openmode when they each support hardcoded directions (insertion,
extraction, both)? I.e., I can do:

   std::ostringstream os(std::ios_base::in);
   // 27.7.3.1 "Constructs and object ... and initializing [stringbuf]
   //           with [supplied openmode] | ios_base::out"

   os << "Random " << 32 << " inputs";

but even though I've specified 'in' in the constructor, the compiler
will complain if I attempt to write:

   std::string sample;
   os >> sample;

So what material in the standard supports the openmode argument?

--
Don Wakefield                              Mentor Graphics Corporation
(503) 685-1262                             8005 S.W. Boeckman Road
don_wakefield@mentorg.com                  Wilsonville, OR 97070-7777

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]