本文介绍了FSEEK VS退?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我注意到两个方法返回到文件的开头
I have noticed two methods to return to the beginning of a file
FILE *fp = fopen("test.bin", "r")
fseek(fp, 0, SEEK_END);
rewind(fp);
和
FILE *fp = fopen("test.bin", "r")
fseek(fp, 0, SEEK_END);
fseek(fp, 0, SEEK_SET);
会有什么区别,如果这些方法之间的?
What would be difference if any between these methods?
推荐答案
他们基本上有两种不同的方式来完成同样的事情:将指针设置为文件的开头。唯一的区别是,退
也清除错误指示器。
They are basically two different ways to accomplish the same thing: set the pointer to the beginning of the file. The only difference is that rewind
also clears the error indicator.
如果有选择,你应该使用 fseek的
。这是因为退
不返回一个整数,指示操作是否成功。
If given the choice, you should use fseek
. This is because rewind
doesn't return an integer indicating whether the operation has succeeded.
这篇关于FSEEK VS退?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!