从istream对象复制(不提取)数据 [英] COPYING (not extracting) data from an istream object

查看:108
本文介绍了从istream对象复制(不提取)数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法做到这一点?我已经尝试过tellg(),然后是seekg(),

将流缓冲区插入到ostringstream(ala os<< is.rdbuf()),

读(),没有运气。


问题是,所有这些方法都在一个或另一个点上提取数据。另一个问题是,似乎没有

获取流中字符

的实际缓冲区指针(char *)的方法。有一种方法可以获得与流相关的streambuf对象

(rdbuf()),但是streambuf对象的gptr()成员

函数受到保护。 br />

帮助!!!


--Randy Yates

Is there any way to do this? I''ve tried tellg() followed by seekg(),
inserting the stream buffer to an ostringstream (ala os << is.rdbuf()),
read(), and having no luck.

The problem is, all of these methods EXTRACT the data at one
point or another. The other problem is there appears to be NO
WAY to get at the actual buffer pointer (char*) of the characters
in the stream. There is a way to get the streambuf object
associated with the stream (rdbuf()), but the gptr() member
function of the streambuf object is protected.

Help!!!

--Randy Yates

推荐答案

>问题是,所有这些方法都在一个
>The problem is, all of these methods EXTRACT the data at one
点或另一个点上提取数据。另一个问题是,似乎没有什么方法可以获得流中字符
的实际缓冲区指针(char *)。有一种方法可以获得与流相关的streambuf对象(rdbuf()),但是streambuf对象的gptr()成员函数受到保护。
point or another. The other problem is there appears to be NO
WAY to get at the actual buffer pointer (char*) of the characters
in the stream. There is a way to get the streambuf object
associated with the stream (rdbuf()), but the gptr() member
function of the streambuf object is protected.




一次可以有多少个流?如果我打开文件ifstream

fin1(" blah.txt")和ifstream fin2(" blah.txt"),那么是fin1和fin2

副本彼此或他们都引用相同的流?


另一个问题浮现在脑海中:你拿了一个输出流,并复制了

它。如果你刷新两个流,让我们一次在(OT)线程中说

(/ OT)是在某处定义的行为吗?



How many streams can you have at one time? If I open a file ifstream
fin1("blah.txt") and ifstream fin2("blah.txt"), then are fin1 and fin2
copies of each other or are they both referencing the same stream?

Another question comes to mind: you took an output stream, and copied
it. If you flush both streams, lets say at one time in a (OT) thread
(/OT) is the behavior defined somewhere?

Shark,


我不明白你的第一个问题,我不会理解你的第二个问题所有。

第一个问题的答案是一个。在这种情况下,我只会在

时间打开一个流。


--Randy

Shark,

I don''t understand the point of your first question, and I don''t
understand your second question at all. The answer to the
first question is "one." I will only have one stream open at a
time in this context.

--Randy


>我不明白你的第一个问题,我不会
>I don''t understand the point of your first question, and I don''t
完全理解你的第二个问题。第一个问题的答案是一个。在这种情况下,我只会在一个时间段打开一个流。
understand your second question at all. The answer to the
first question is "one." I will only have one stream open at a
time in this context.




哦对不起,我的问题是广泛的你的观众。其中

你和我是子集:)


基本上我们一次可以拥有多少个流,这些就像是一条河流的小支流? std out,ofstream来自ostream

等等,但最终是这些流组合在一起还是它们都有所不同

方式?


假设可以复制标准输出流并且存在各种副本。

如果我们使用endl冲洗它们,我们是否会观察到定义的

行为?



oh sorry about that, my question was to a broad "you audience" of which
"you" and "me" are subsets :)

Basically how many streams can we have at one time, and are these like
little tributaries to a river? std out, ofstream derive from ostream
etc. but in the end are these streams combined or they all go different
ways?

Suppose standard output stream can be copied and various copies exist.
If we flush each of them using endl, will we observe a defined
behavior?


这篇关于从istream对象复制(不提取)数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆