fgetpos/fsetpos和ftell/fseek有什么区别 [英] what is difference between fgetpos/fsetpos and ftell/fseek

查看:414
本文介绍了fgetpos/fsetpos和ftell/fseek有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用功能fgetpos()fsetpos()以及使用功能ftell()fseek()来获取和设置文件位置之间有什么区别?

What's the difference between using the functions fgetpos() and fsetpos() and using the functions ftell() and fseek() to get and set a position in a file?

fgetpos()fsetpos()有什么用处?为什么要使用它们代替ftell()fseek()?

What are fgetpos() and fsetpos() good for? Why would they be used instead of ftell() and fseek()?

推荐答案

从手册页中我们可以看到ftell和fseek使用long int类型表示文件中的偏移量(位置),因此可能仅限于偏移量可以用long int表示. (不能保证long int类型保存的值大于2 ** 31-1,将最大偏移量限制为2 GB).另一方面,较新的fgetpos和fsetpos函数使用特殊的typedef fpos_t表示偏移量.这背后的typedef的类型,如果适当选择,可以表示任意大的偏移,因此fgetpos和fsetpos可以与任意巨大文件中使用. fgetpos和fsetpos还会记录与多字节流关联的状态.

Well, from the manpage we can see that ftell and fseek use type long int to represent offsets (positions) in a file, and may therefore be limited to offsets which can be represented in a long int. (Type long int is not guaranteed to hold values larger than 2**31-1, limiting the maximum offset to 2 gigabytes). The newer fgetpos and fsetpos functions, on the other hand, use a special typedef, fpos_t, to represent the offsets. The type behind this typedef, if chosen appropriately, can represent arbitrarily large offsets, so fgetpos and fsetpos can be used with arbitrarily huge files. fgetpos and fsetpos also record the state associated with multibyte streams.

这篇关于fgetpos/fsetpos和ftell/fseek有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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