二进制文件和ascii文件之间的差异 [英] differance between binary file and ascii file

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

问题描述

你好。每个人

Plz告诉二进制文件和ascii之间的区别

文件...............

谢谢

提前

vim

hello everybody
Plz tell the differance between binary file and ascii
file...............
Thanks
in advance
vim

推荐答案

vim说:
vim said:
大家好。
Plz告诉二进制文件和ascii
文件之间的区别...............
hello everybody
Plz tell the differance between binary file and ascii
file...............




嗯,这确实是错误的问题。


正确的问题是:有什么区别?在
二进制模式下打开的流,以及在文本模式下打开的流?


让我们首先处理简单的流。当您将二进制流与

a文件关联时,数据从文件流入,流未经修改的

(或者,如果您正在编写,则会流动通过流,到文件,

未修改)。它只是一个原始的字节流,可以随意使用。


好​​的,现在很难。当你将/ text / stream与一个文件关联起来时,你b $ b假设数据包含零行或多行的约定,

其中每一行由0或更多字节后跟换行标记

某种类型。


由C定义的换行标记为''\ n''。


在Unix上,这与该系统上长期

惯例实际使用的标记很吻合。


在CP / M上和衍生物(例如Q-DOS和点击冒险
它产生的
游戏),标记是''\ r''和''\ n'',在那里订单。


在Mac上,它只是简单地''\ r''。


在大型机上 - 好吧,你/我真的/不想知道。


这一切都有点令人讨厌,如果我们没有必要那就好了

在处理普通文本时会有这样的细节。因此,当您从文本流中读取
时,标准库会对传入的数据执行任何必要的

转换,将新行标记强制映射为一个好的

简单''\ n''。当你写入流时,标准库

会查找''\ n''字符,并用

标记换行符的字节或字节替换它们在程序运行的特定系统上。


所以,当你编写代码时,你可以假装换行符

标记是' '\ n'',以及 - 所有意图和目的 - 所以它是!因此,你不会因为检测到你是在Mac上运行还是在迷你上运行而无需担心,你可以假设一个' '\ n''分隔符,让标准的

库担心底层表示。


如果你不想要/系统到这样做,以二进制模式打开文件。但是

然后管理换行的东西都会落到你身上。


-

Richard Heathfield

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

电子邮件:rjh在上面的域名(但显然放弃了www)



Well, that''s really the wrong question.

The right question is: "what is the difference between a stream opened in
binary mode, and a stream opened in text mode?"

Let''s deal with the easy one first. When you associate a binary stream with
a file, the data flows in from the file, through the stream, unmodified
(or, if you''re writing, it flows out, through the stream, to the file,
unmodified). It''s just a raw stream of bytes, to do with as you will.

Okay, now the hard one. When you associate a /text/ stream with a file, you
are assuming the convention that the data comprises zero or more lines,
where each line is composed of 0 or more bytes followed by a newline marker
of some kind.

The newline marker defined by C is ''\n''.

On Unix, this agrees well with the marker actually used by longstanding
convention on that system.

On CP/M and derivatives (such as Q-DOS and that point-and-click adventure
game it spawned), the marker is ''\r'' and ''\n'', in that order.

On the Mac, it''s just plain ''\r''.

On the mainframe - well, you /really/ don''t want to know.

All this is a bit of a nuisance, and it would be nice if we didn''t have to
bother with such niceties when processing plain ol'' text. And so, when you
are reading from a text stream, the standard library performs any necessary
conversions on incoming data, to force-map the newline marker into a nice
simple ''\n''. And when you are writing to the stream, the standard library
looks for ''\n'' characters and replaces them with the byte or bytes used for
marking newlines on the particular system on which the program is running.

So, when you are writing your code, you can just pretend that the newline
marker is ''\n'', and - to all intents and purposes - so it is! So you don''t
have to mess about with detecting whether you''re running on a Mac or a mini
or a mainframe - you can just assume a ''\n'' delimiter and let the standard
library worry about the underlying representation.

If you don''t /want/ the system to do this, open the file in binary mode. But
then managing the newline stuff all falls to you instead.

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


" vim"写道:
"vim" wrote:
Plz告诉二进制文件和ascii
文件之间的区别...............
Plz tell the differance between binary file and ascii
file...............



这是一个关于这个主题的长期和最近的讨论。

http://tinyurl.com/s737d


非常感谢

thanks a lot

这篇关于二进制文件和ascii文件之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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