🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Tim Ottinger Fri, 15 Mar 1996 15:06
istrstreams and width
#3687
Author: Tim Ottinger
Date: Fri, 15 Mar 1996 15:06
41 lines
2476 bytes
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                             ]
Re: istrstreams and width
#3735
Author: Bob Kline
Date: Tue, 19 Mar 1996 11:17
49 lines
2875 bytes
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                             ]
Re: istrstreams and width
#3803
Author: Rob Stewart
Date: Mon, 25 Mar 1996 18:22
43 lines
2373 bytes
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 
]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads