从流中读取直到EOF [英] Reading from a stream til EOF
问题描述
我有一个''std :: istream'',需要把它的全部内容读成一个字符串。怎么能
我这样做?
TIA;
Schobi
-
Sp******@gmx.de 永远不会被阅读>
我是Schobi at suespammers dot org
有时编译器比人们更合理。
Scott Meyers
Hi,
I have a ''std::istream'' and need to read
its whole contents into a string. How can
I do this?
TIA;
Schobi
--
Sp******@gmx.de is never read
I''m Schobi at suespammers dot org
"Sometimes compilers are so much more reasonable than people."
Scott Meyers
推荐答案
Hendrik Schober写道:
Hendrik Schober wrote:
我有一个''std :: istream''并且需要将其全部内容读成字符串。我怎么能这样做?
TIA;
Schobi
Hi,
I have a ''std::istream'' and need to read
its whole contents into a string. How can
I do this?
TIA;
Schobi
好吧,我不是专家关于STL,但这里有一些例子
例1:
char c;
while(your_istream。 get(c))
your_string.push_back(c);
例2:
char c;
while(your_istream>> c)
your_string.push_back(c);
例3:
string your_string;
while(your_istream>> your_string)
foo();
- -
Rodrigo Dominguez
< ro *** @ rorra.com.ar>
Powered Hosting
( www.powered-design.com )
< br>
Rodrigo Dominguez< ro *** @ rorra.com.ar>写道:
Rodrigo Dominguez <ro***@rorra.com.ar> wrote:
Hendrik Schober写道:
Hendrik Schober wrote:
我有''std :: istream''并需要将其全部内容读成字符串。我怎么能这样做?
TIA;
Schobi
Hi,
I have a ''std::istream'' and need to read
its whole contents into a string. How can
I do this?
TIA;
Schobi
好吧,我不是STL的专家,但是这里有一些例子
[...]
well, I''m not an expert on STL, but here are some examples
[...]
实际上我希望有一些能够带来更多性能的东西
。 br />
Schobi
-
Sp******@gmx.de 永远不会被阅读
我是Schobi at suespammers dot org
有时候编译器比人们更合理。
Scott Meyers
Actually I was hoping for something
that would promiss more performance.
Schobi
--
Sp******@gmx.de is never read
I''m Schobi at suespammers dot org
"Sometimes compilers are so much more reasonable than people."
Scott Meyers
" Hendrik Schober" < SP ****** @ gmx.de>在消息中写道
news:c1 ********** @ news1.transmedia.de ...
"Hendrik Schober" <Sp******@gmx.de> wrote in message
news:c1**********@news1.transmedia.de...
>我有一个''std :: istream''并且需要将其全部内容读成字符串。我怎么能这样做?
Hi,
I have a ''std::istream'' and need to read
its whole contents into a string. How can
I do this?
我害怕在某些时候制作副本是不可避免的。我希望你
可以调用reserve(),然后直接写入底层的
存储,就像vector一样 - 至少如果字符串从未出现过
复制。
Jonathan
I''m afraid making a copy at some point is unavoidable. I wish you
could call reserve() and then write directly into the underlying
storage, as with vector -- at least if the string had never been
copied.
Jonathan
这篇关于从流中读取直到EOF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!