wilson@ac5.cs.nps.navy.mil (kalin wilson) (04/11/91)
Is there a simple way to use a string as an input object. Something built into the standard (?) iostream classes? What I want to do is similiar to sscanf with an input stream or sprintf with an output stream. I want to attach the stream to a string then use extractors to process the string. Maybe this is undo duplication. I'd like to stay away from printf type functions because of some of the excess baggage they have. It seems this type of capability would be a logical OOP use of streams and strings. -------------------------------------------------------------------- Kalin Wilson | wilson@taurus.cs.nps.navy.mil Naval Postgraduate School | Monterey, Ca | "Opinions? What opinions?" -------------------------------------------------------------------
dagenais@siegfried.vlsi.polymtl.ca (Michel Dagenais) (04/11/91)
In libg++ there is an istream constructor which accepts a buffer as argument instead of a file name. Sounds like the solution to your problem. You can probably even redefine the internal underflow member function to handle data buffered by chunks... like a long object spread several pages in a disk BTREE implementation :-). -- --------------------------------------------------------------------------- Michel Dagenais dagenais@vlsi.polymtl.ca Ecole Polytechnique de Montreal tel: (514) 340-4029 ---------------------------------------------------------------------------
mittle@blinn.watson.ibm.com (Josh Mittleman) (04/11/91)
In article <2072@ac5.cs.nps.navy.mil>, wilson@ac5.cs.nps.navy.mil (kalin wilson) writes: > Is there a simple way to use a string as an input object. Yes. You want to use istrstreams and ostrstreams. Lippman's C++ Primer has a good description in section A.8, Incore Formatting, beginning p.409.
mlanett@ncsa.uiuc.edu (Mark Lanett) (04/12/91)
In article <DAGENAIS.91Apr11092631@pollux.siegfried.vlsi.polymtl.ca>, dagenais@siegfried.vlsi.polymtl.ca (Michel Dagenais) writes: > In libg++ there is an istream constructor which accepts a buffer as > argument instead of a file name. Sounds like the solution to your problem. > You can probably even redefine the internal underflow member function to > handle data buffered by chunks... like a long object spread several pages > in a disk BTREE implementation :-). > -- > --------------------------------------------------------------------------- > > Michel Dagenais dagenais@vlsi.polymtl.ca > Ecole Polytechnique de Montreal tel: (514) 340-4029 > > --------------------------------------------------------------------------- A better solution is the iostream library's strstreambuf. Use istrstream (buf, sizeof (buf)) and ostrstream (buf, sizeof (buf)) to create the strstreams. You can insert and extract from them as with istream and ostream.-- //----------------------------------------------------- Mark Lanett, mark-lanett@uiuc.edu NCSA, Software Tools Group, mlanett@ncsa.uiuc.edu