二进制模式??? [英] Binary mode???

查看:100
本文介绍了二进制模式???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们应该使用文件的二进制模式?实际需要的地方

???

Why we should use binary mode of file? Where it is going to be
actually needed???

推荐答案

文章< 11 * *********************@j4g2000prf.googlegroups。 com>,

Shraddha< sh ************* @ gmail.comwrote:
In article <11**********************@j4g2000prf.googlegroups. com>,
Shraddha <sh*************@gmail.comwrote:

> ;为什么我们应该使用文件的二进制模式?实际需要的地方???
>Why we should use binary mode of file? Where it is going to be
actually needed???



MS Windows。那些文本文件的行由

回车+换行对分隔,这对在文本模式下一起读取

作为单个\ n。如果您使用文本模式尝试
写出二进制数据文件,并且碰巧写出了

a换行(很可能是偶然的任何重要文件

大小)然后,而不是只有换行输出,两个

回车和换行将被输出(在那个特定的
平台上。)在很多情况下都会破坏文件。


-

有些想法错了,只有一个非常聪明的人

可以相信它们。 - George Orwell

MS Windows. Text files there have their lines delimited by
carriage return + linefeed pairs, the pair together reading in
as a single \n in text mode. If you used text mode to try to
write out a file of binary data, and happened to write out
a linefeed (pretty likely by chance in a file of any significant
size) then instead of having just the linefeed output, both
carriage return and linefeed would be output (on that particular
platform.) That''s going to ruin the file in many circumstances.

--
There are some ideas so wrong that only a very intelligent person
could believe in them. -- George Orwell


Shraddha说:
Shraddha said:

为什么我们应该使用文件的二进制模式?
Why we should use binary mode of file?



如果您的意思是我们为什么要以二进制模式打开文件?,答案是

因为我们想要以字节原始流的形式访问文件,而不是以换行符分隔的文本文件形式访问文件。

If you mean "why should we open a file in binary mode?", the answer is
"because we want to access the file as a raw stream of bytes, rather
than as a newline-delimited text file."


它在哪里真的需要???
Where it is going to be actually needed???



当你打开一个不是普通文本文件的文件,或者当你想要访问一个文件时,你需要

普通的文本文件好像不是一个。


-

Richard Heathfield

Usenet是一个奇怪的放置" - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名, - www。

When you''re opening a file that isn''t an ordinary text file, or even
when you want to access an ordinary text file as if it weren''t one.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


2007年6月21日星期四10:30:15 - 0700,在comp.lang.c,Shraddha

< sh ************* @ gmail.comwrote:
On Thu, 21 Jun 2007 10:30:15 -0700, in comp.lang.c , Shraddha
<sh*************@gmail.comwrote:

>为什么我们应该使用文件的二进制模式?实际需要的地方???
>Why we should use binary mode of file? Where it is going to be
actually needed???



如果您正在存储或读取二进制数据,请使用二进制模式。


任何OSen翻译某些字符时为什么?用文本写的

模式 - 比如行尾标记,文件结束标记等。

所以如果你用文字写出一个JPEG图像模式,数据将是b $ b $乱码。反过来,当你再次阅读它的时候也是如此。


顺便说一下,windows并不是唯一能做到这一点的操作系统,并不是所有操作系统都能做到br />
它的方式相同 - MacOS,MSDOS,VMS(我认为)可能CP / M和

可能TOS和AmigaDos似乎都这样做,但不是在同一个< br $>
方式。


我自己,我认为Unix错了 - 回到我的

电传打字机的下一行,我绝对是需要CR和LF ......


-

马克麦金太尔


"调试是第一次编写代码的两倍。

因此,如果你尽可能巧妙地编写代码,那么,根据定义你是b $ b,不够聪明调试它。

--Brian Kernighan

If youre storing or reading binary data, use binary mode.

any OSen translate certain characters when tehy''re written in text
mode - such as the end-of-line marker, the end-of-file marker etc.
So if you wrote a JPEG image out using text mode, the data would be
garbled. Ditto, in reverse, when you''re reading it back in again.

By the way, windows isn''t the only OS to do this, and not all OSes do
it the same way - MacOS, MSDOS, VMS (I think) probably CP/M and
probably TOS and AmigaDos all seem to do it, though not in the same
way.

Myself, I think Unix has it wrong - to return to the next line on my
teletype, I definitely need a CR and an LF.....

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan


这篇关于二进制模式???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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