Topic: istrstreams and width
Author: Rob Stewart <stew@datalytics.com>
Date: 1996/03/25 Raw View
Tim Ottinger wrote:
>
> We've already worked around this (identified two way to do so) but we
> wonder why it doesn't work this way:
>
> Given:
> istrstream source;
> int i;
> string s;
> source >> setw(2) >> i >> s;
>
> With fixed length fields (yes, we have to read mainframe data from time to
> time, and a few other odd sources), sometimes the fields are butted up against
> each other, and sometimes the strings have initial digit characters i them.
>
> When the stream contains "01115 N Neil", it would be nice if "01" and "115 N
> Neil" were broken out, but every compiler we try pulls "01115" as the number,
> and "N Neil" is the string.
>
> Of course, if we insert whitespace or use read, this works. And we should use
> read() because we're doing fixed length, but I was wondering why setw()
> doesn't apply to integer extractors.
>
> Surely a lot of people have to read fixed-length records, and this is a common
> thing.
>
> Any thoughts?
The setw manipulator, like the width mf, only specify a minimum
field width. Thus, neither was intended to indicate the maximum
number of characters to read. You only solutions are to use
read or to parse the longer string yourself.
--
Robert Stewart | My opinions are usually my own.
Datalytics, Inc. | stew@datalytics.com
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: bkline@cortex.nlm.nih.gov (Bob Kline)
Date: 1996/03/19 Raw View
I have asked this question (with respect to the istream spec in general)
from time to time in this forum, and (until reading your article) have
always attributed the lack of response to the theory that everyone else
on the newsgroup was too young to understand what I was talking about.
:->} Seriously, though, it would be nice if the newer I/O model provided
at least the level of support for formatted I/O as the model it purports
to replace, but there doesn't seem to be much interest.
Tim Ottinger (tottinge@csci.csc.com) wrote:
: We've already worked around this (identified two way to do so) but we
: wonder why it doesn't work this way:
: Given:
: istrstream source;
: int i;
: string s;
: source >> setw(2) >> i >> s;
: With fixed length fields (yes, we have to read mainframe data from time to
: time, and a few other odd sources), sometimes the fields are butted up
: against each other, and sometimes the strings have initial digit characters
: i them.
: When the stream contains "01115 N Neil", it would be nice if "01" and
: "115 N Neil" were broken out, but every compiler we try pulls "01115"
: as the number, and "N Neil" is the string.
: Of course, if we insert whitespace or use read, this works. And we should
: use read() because we're doing fixed length, but I was wondering why setw()
: doesn't apply to integer extractors.
: Surely a lot of people have to read fixed-length records, and this is a
: common thing.
: Any thoughts?
: Tim
--
/*----------------------------------------------------------------------*/
/* Bob Kline Stream International */
/* bob_kline@stream.com formerly Corporate Software, Inc. */
/* voice: (703) 522-0820 x-311 fax: (703) 522-5407 */
/*----------------------------------------------------------------------*/
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: tottinge@csci.csc.com (Tim Ottinger)
Date: 1996/03/15 Raw View
We've already worked around this (identified two way to do so) but we
wonder why it doesn't work this way:
Given:
istrstream source;
int i;
string s;
source >> setw(2) >> i >> s;
With fixed length fields (yes, we have to read mainframe data from time to
time, and a few other odd sources), sometimes the fields are butted up against
each other, and sometimes the strings have initial digit characters i them.
When the stream contains "01115 N Neil", it would be nice if "01" and "115 N
Neil" were broken out, but every compiler we try pulls "01115" as the number,
and "N Neil" is the string.
Of course, if we insert whitespace or use read, this works. And we should use
read() because we're doing fixed length, but I was wondering why setw()
doesn't apply to integer extractors.
Surely a lot of people have to read fixed-length records, and this is a common
thing.
Any thoughts?
Tim
******************************************************************************
* Tim Ottinger, Sr Tech tottinge@csci.csc.com *
* CSC Communications Industry Services 217-351-8508x2420 *
* TRIS Division -- Cellular Billing and Support Fax 217-351-2640 *
******************************************************************************
* Requirements have always been the least stable part of any project I have *
* worked upon. -- Robert Martin via Usenet 12/02/95 *
******************************************************************************
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]