Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Make copy of input stream

1 view
Skip to first unread message

John Keenan

unread,
Jul 24, 2009, 1:04:29 AM7/24/09
to
Is it possible to make a copy of an input stream? I would like to make a
copy of an input stream which uses the same buffer as the original but has
its own position and state which are initialized to the original stream's
position and state. I am not seeing this in Josuttis but wanted to ask in
case I am missing something.

John

Ulrich Eckhardt

unread,
Jul 24, 2009, 2:44:58 AM7/24/09
to
John Keenan wrote:
> Is it possible to make a copy of an input stream? I would like to make a
> copy of an input stream which uses the same buffer as the original but has
> its own position and state which are initialized to the original stream's
> position and state.

No. The input stream may well be non-seekable, which means you can't just
reference a position in there. If you tell us what you're trying to do,
there might be further suggestions.

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

John Keenan

unread,
Jul 24, 2009, 9:59:09 AM7/24/09
to
Ulrich wrote:

> No. The input stream may well be non-seekable, which means you can't just
reference a position in there.

The input stream I wish to copy will always be seekable.

> If you tell us what you're trying to do, there might be further
suggestions.

I am modifying a language parser. I would like to bury the management of
tellg and seekg into a class.

John

Scot T Brennecke

unread,
Jul 25, 2009, 4:31:07 PM7/25/09
to

Ah, now it's clear that the "input stream" you mean is the basic_istream type provided in the Standard C++ Library. istream,
ifstream and istrstream are already classes. Note that the iostreams are not part of STL; STL and iostreams are both part of the
Std C++ Lib, though.

I believe that if you use the same string pointer to construct two istrstreams, for instance, you'll get two independently-
traversing stream objects on the same underlying input string.

What do you really need?

Stephan T. Lavavej [MSFT]

unread,
Jul 27, 2009, 1:55:39 PM7/27/09
to
Please note that strstreams (in <strstream>) and stringstreams (in
<sstream>) are very different things. <strstream> is ancient
pre-Standardization machinery. Don't use it - it's really awful and
horrible stuff. (It's in Annex D of C++03, the deprecated features section,
along with other really horrible stuff like the conversion from string
literals to char *, and stuff that isn't particularly evil and will survive
forever, like namespace-scope static.) In constrast, <sstream> offers the
usual level of iostreams quality.

Stephan T. Lavavej
Visual C++ Libraries Developer

"Scot T Brennecke" <Sc...@Spamhater.MVPs.org> wrote in message
news:uGZAYbWD...@TK2MSFTNGP04.phx.gbl...

John Keenan

unread,
Jul 28, 2009, 12:20:24 PM7/28/09
to
Scot wrote:

> Note that the iostreams are not part of STL; STL and iostreams are both
part of the Std C++ Lib, though.

I knew that but it completely slipped my mind. What would be a more
appropriate newsgroup for this question?

> What do you really need?

Method rdbuf is what I was looking for.

John

Scot T Brennecke

unread,
Jul 29, 2009, 1:53:12 AM7/29/09
to
John Keenan wrote:
> Scot wrote:
>
>> Note that the iostreams are not part of STL; STL and iostreams are both
> part of the Std C++ Lib, though.
>
> I knew that but it completely slipped my mind. What would be a more
> appropriate newsgroup for this question?

I really meant that to be "FYI". I don't know of a better newsgroup than this one for this type of question.

0 new messages