使用文件中的提取运算符分隔行的空格 [英] Whitespace separating lines using extraction operator on file

查看:50
本文介绍了使用文件中的提取运算符分隔行的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我打开了一个文件,称之为infile。我有一个简单的时间(!eof),

但是说我的文件的第一行是<?xml version =" 1.0">,然后它获取

两次迭代来获取字符串。第一个''line''是"<?xml",然后''line''是

" version =" 1.0"",我需要的是什么改变这样的行为,我可以得到文件中换行符分隔的行吗?


std :: string line;

std :: ifstream infile(&whatever.txt",std :: ios_base :: in);

while(!infile.eof())

{

infile>> line;

std :: cout<< line<< std :: endl;

line ="" ;;

}

infile.close();


感谢您的时间,

Kevin Grigorenko

Okay, i''ve got a file open, call it infile. I''ve got a simple while(!eof),
but say the first line of my file is "<?xml version="1.0">", then it takes
two iterations to get the string. first ''line'' is "<?xml", then ''line'' is
"version="1.0"", what''s happening that I need to change the behavior of so
that I can get lines delimitted by the newlines in the file?

std::string line;
std::ifstream infile("whatever.txt", std::ios_base::in);
while(!infile.eof())
{
infile >> line;
std::cout << line << std::endl;
line = "";
}
infile.close();

Thanks for your time,
Kevin Grigorenko

推荐答案

" Kevin Grigorenko" < KZ **** @ psu.edu>写了
"Kevin Grigorenko" <kz****@psu.edu> wrote
好的,我有一个文件打开,称之为infile。我有一个简单的时间(!eof),
但是我的文件的第一行是<?xml version =" 1.0">,然后需要
两次迭代来获取字符串。 first''line''是"<?xml",然后''line''是
" version =" 1.0"",我需要改变行为的是什么那么
我可以通过文件中的换行符分隔行吗?
Okay, i''ve got a file open, call it infile. I''ve got a simple while(!eof),
but say the first line of my file is "<?xml version="1.0">", then it takes
two iterations to get the string. first ''line'' is "<?xml", then ''line'' is
"version="1.0"", what''s happening that I need to change the behavior of so
that I can get lines delimitted by the newlines in the file?




这在FAQ中有介绍。祝你好运。


问候,

巴斯特



This is covered in the FAQ. Good luck.

Regards,
Buster


" Buster" <无*** @ nowhere.com>在消息中写道

news:bk ********** @ news6.svr.pol.co.uk ...
"Buster" <no***@nowhere.com> wrote in message
news:bk**********@news6.svr.pol.co.uk...
" Kevin Grigorenko" < KZ **** @ psu.edu>写了
"Kevin Grigorenko" <kz****@psu.edu> wrote
好的,我有一个文件打开,称之为infile。我有一个简单的
而(!eof),但是我的文件的第一行是<?xml version =" 1.0">,然后是
需要两次迭代来获取字符串。第一个''line''是"<?xml",然后''line''
是" version =" 1.0"",我需要改变行为的是什么
,以便我可以通过文件中的换行符分隔行?
Okay, i''ve got a file open, call it infile. I''ve got a simple while(!eof), but say the first line of my file is "<?xml version="1.0">", then it takes two iterations to get the string. first ''line'' is "<?xml", then ''line'' is "version="1.0"", what''s happening that I need to change the behavior of so that I can get lines delimitted by the newlines in the file?



这在FAQ中有介绍。祝你好运。

问候,
巴斯特



This is covered in the FAQ. Good luck.

Regards,
Buster




指出懒惰是好的,但你可以至少只是给了我

一些要看的部分。这个论坛上的每个问题都已在某个时间点在互联网上的某个地方得到回答,但搜索很痛苦

且乏味,这就是为什么人们会问同样的问题

新闻组中一遍又一遍的问题 - 它节省了时间。当我还是个孩子的时候,我没有时间,所以我试着在论坛中引起好心人的帮助。所以

请在将来不要只告诉别人那是在某处。

祝你好运。这是一个非常荒谬而明显的答案。


我会根据您的建议查看常见问题解答,并希望其他人

多一点同情将在该时间范围内回复并指向

a更多离散方向。


Kevin Grigorenko



It''s fine to point out laziness, but you could have at minimum just given me
some section to look at. Every question on this forum has been answered
somewhere on the internet at some point in time, but searching is painful
and tedious, that''s why people ask the same questions over and over again in
newsgroups - it saves time. I don''t have the time I once had when I was a
teenager, so I try to elicit the help of the nice people in forums. So
please in the future do not just tell people "That is covered somewhere.
Good luck." That is a pretty ridiculous and obvious answer.

I will look at the FAQ as per your suggestion and hope that someone else
with a little bit more sympathy will reply in that timeframe and point me to
a more discrete direction.

Kevin Grigorenko




" Kevin Grigorenko" < KZ **** @ psu.edu>写了

"Kevin Grigorenko" <kz****@psu.edu> wrote
可以指出懒惰
我没有这么说。

但你可以至少给出我看看有些部分。
好​​的。
http://www.parashift.com/c++-faq-lit...t.html#faq-5.5

此论坛上的每个问题都已得到解答<在某个时间点在互联网的某个地方,但搜索是痛苦的和乏味的。
所以我应该为你做这件事吗?

这就是为什么人们在
新闻组中一遍又一遍地问同样的问题 - 这样可以节省时间。
他们的时间。

我没有时间,当我还是青少年时,我没有时间,所以我试着在论坛中引起好人的帮助。所以
请将来不要只告诉别人那是在某处。
祝你好运。这是一个非常荒谬而明显的答案。
很明显,是的。荒谬,没有。

我会根据你的建议查看常见问题解答,并希望有更多同情的人会在那段时间内回复并指出我
一个更离散的方向。
It''s fine to point out laziness I didn''t say that.
but you could have at minimum just given me
some section to look at. OK.
http://www.parashift.com/c++-faq-lit...t.html#faq-5.5
Every question on this forum has been answered
somewhere on the internet at some point in time, but searching is painful
and tedious. So I should do it for you?
that''s why people ask the same questions over and over again in
newsgroups - it saves time. Their time.
I don''t have the time I once had when I was a
teenager, so I try to elicit the help of the nice people in forums. So
please in the future do not just tell people "That is covered somewhere.
Good luck." That is a pretty ridiculous and obvious answer. Obvious, yes. Ridiculous, no.
I will look at the FAQ as per your suggestion and hope that someone else
with a little bit more sympathy will reply in that timeframe and point me to
a more discrete direction.



也许,我帮助的下一个人再也不会对我无礼了。

我不喜欢尽管如此,还是抱有很大希望。


再次,祝你好运。

巴斯特。


And just maybe, the next person I help won''t be gratuitously rude to me, again.
I don''t hold out much hope though.

Again, good luck.
Buster.


这篇关于使用文件中的提取运算符分隔行的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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