Victor Bazarov <v.Abazarov@comAcast.net> writes:
[color=blue]
> Randy wrote:[color=green]
>> I have one and only one question: How do you COPY N characters in
>> an input stream into a char buffer[N] array? I'd appreciate an answer
>> to that question.[/color]
>
> Have you tried implementing it yourself?[/color]
Yes, albeit not very hard. I guess I'm waffling between doing that and
thinking there must be a better way.
As I said, I also can't see a way to get at the actual character
pointer that must be buried somewhere. I suppose I could create a
class that derives from streambuf() and then expose the
Has NO one EVER wanted to "peek" (at more than one character at a
time) into an extractor stream???? I'm amazed the istream class
doesn't provide this function "out-of-the-box."
I mentioned in another post *why* I'm trying to do this:
I'm creating a set of classes for some functions that require
lots of parameters. A simple, human-readable and -controllable
way to do this is to overload the inserter and extractor
operators to report and control these parameters as
property/value pairs, e.g., "ParameterA=value1".
The idea is to feed a list of property/value pairs to the top-level
class, have his extractor interpret and set the properties that
pertain to it (and ignore those that don't), then pass the entire set
to the child classes, the children to their grandchildren, etc.
(speaking hierarchically and/or inheritance-wise).
So, I need to operate on an istream without wasting the
string (or stream) in it.
Is this so unusual? Am I mis-using the extractor class or abusing the
operators somehow by wanting to do this?
[color=blue]
> I'd look into 'sgetn' and all
> the positioning functions for the stream buffer... The idea is to first
> preserve the position of the buffer by calling
>
> pos_type pos = os.pubseekoff(0, ...); // look up the other arguments
>
> then
>
> int got = os.sgetn(where, N);
>
> and then restore the position
>
> os.pubseekpos(pos, ..
>
> Of course you can run into a streambuf implementation that can't really
> set its position, but for files it should work fine.[/color]
That's just it - these aren't necessarily file streams, and I've found,
at least within the istream class, that tellg() and seekg() don't work
with non-file streams. I'm thinking these gets and seeks won't either.
--
% Randy Yates % "Midnight, on the water...
%% Fuquay-Varina, NC % I saw... the ocean's daughter."
%%% 919-577-9882 % 'Can't Get It Out Of My Head'
%%%% <yates@ieee.org> % *El Dorado*, Electric Light Orchestra
http://home.earthlink.net/~yatescr