fopen中r和rb有什么区别 [英] what's the differences between r and rb in fopen

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

问题描述

我尝试在 C 中使用 fopen,第二个参数是打开模式.两种模式r"和rb"往往让我很困惑.似乎他们是一样的.但有时最好使用rb".那么,为什么r"存在?向我详细解释或举例说明.谢谢你.

I tried using fopen in C, the second parameter is the open mode. The two modes "r" and "rb" tend to confuse me a lot. It seems they are the same. But sometimes it is better to use "rb". So, why does "r" exist? Explain it to me in detail or with examples. Thank You.

推荐答案

您应该使用 "r" 打开文本文件.不同的操作系统存储文本的方式略有不同,这将执行正确的翻译,因此您无需了解本地操作系统的特性.例如,您将知道换行符将始终显示为简单的 " ",无论代码在哪里运行.

You should use "r" for opening text files. Different operating systems have slightly different ways of storing text, and this will perform the correct translations so that you don't need to know about the idiosyncracies of the local operating system. For example, you will know that newlines will always appear as a simple " ", regardless of where the code runs.

如果您打开非文本文件,您应该使用 "rb",因为在这种情况下,翻译是不合适的.

You should use "rb" if you're opening non-text files, because in this case, the translations are not appropriate.

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

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