fgets()和fread()-有什么区别? [英] fgets() and fread() - What is the difference?

查看:91
本文介绍了fgets()和fread()-有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解 fgets() fgetss() ,但我没有得到 fgets() fread() ,有人可以澄清一下这个主题吗?哪一个更快?谢谢!

I understand the differences between fgets() and fgetss() but I don't get the difference between fgets() and fread(), can someone please clarify this subject? Which one is faster? Thanks!

推荐答案

fgets 读取一行-即它将在换行处停止.

fgets reads a line -- i.e. it will stop at a newline.

fread 读取原始数据-它将在指定的(或默认)个字节数后停止,与可能存在或可能不存在的任何换行符无关.

fread reads raw data -- it will stop after a specified (or default) number of bytes, independently of any newline that might or might not be present.


速度不是一个在另一个上使用的理由,因为这两个功能根本做不到相同的事情:


Speed is not a reason to use one over the other, as those two functions just don't do the same thing :

  • 如果您想从文本文件中读取一行,请使用 fgets
  • 如果要从文件中读取某些数据(不一定是一行),请使用
  • If you want to read a line, from a text file, then use fgets
  • If you want to read some data (not necessarily a line) from a file, then use fread.

这篇关于fgets()和fread()-有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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