使用ifstream读取最后一行txt文件两次 [英] Last line of txt-file read twice with ifstream

查看:66
本文介绍了使用ifstream读取最后一行txt文件两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在使用ifstream从txt文件中读取数据,但最后一行总是被读取两次。怎么来的?


读取文件的循环的条件是


while(!infile.eof())


所以这对我来说似乎很奇怪。有没有人有如何解决这个问题的建议?

Hi,

I''m using ifstream to read data from a txt-file but the last line is always read twice. How Come?

The condition for the loop in which the file is read is

while(!infile.eof())

so this seems strange to me. Does anyone have a suggestion how to solve this problem?

推荐答案

嗯...它应该有效,你能发帖子吗?
hmm...it should work, can you post the text file?

当然,txt文件如下所示:

Sure, the txt-file looks like this:

展开 | 选择 | Wrap | 行号



当然,txt文件看起来像这样:

Sure, the txt-file looks like this:

Expan d | 选择 | Wrap | 行号


这篇关于使用ifstream读取最后一行txt文件两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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