Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#面试题37 #76

Open
Niexiaoer opened this issue Mar 5, 2020 · 0 comments
Open

#面试题37 #76

Niexiaoer opened this issue Mar 5, 2020 · 0 comments

Comments

@Niexiaoer
Copy link

在读取Test.txt文件时,将所有的字符打印到屏幕(line 114)
while(!fileIn1.eof())
{
fileIn1 >> ch;
cout << ch;
}
这里会把最后一个字符重新读取两次,因为在读取到最后一个字符时,eof()判断仍为假,这时候就会再进一次函数,但是文件指针仍然停留在最后一个字符,这样最后一个字符就会重复读取。
建议将该段代码改为
while(fileIn1 >> ch)
{
cout << ch;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant