管道:文件(16位)到FILRE(8,16,24bits) [英] Pipe: FILE(16bits) to FILRE(8,16,24bits)

查看:108
本文介绍了管道:文件(16位)到FILRE(8,16,24bits)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以16位为单位读取文件作为BINARY,并以8,16和24位为单位写入另一个文件

作为BINARY。它实际上是一根烟斗。我正在寻找一个简单,可执行和可移植的C ++代码示例的
。可能很优雅

;-)))))提前谢谢。


Dario de Judicibus

解决方案




Dario de Judicibus写道:


我需要以16位为单位读取文件作为BINARY ,并以8,16和24位为单位写入另一个文件
作为BINARY。它实际上是一根烟斗。我正在寻找简单,可执行和可移植的C ++代码示例。可能很优雅
;-))))))提前谢谢。




Aehm。你可能没有正确表达自己。但是以16位块读取
a文件并以8位块写入读取数据

应生成完全相同的文件。

24写入如果原始文件大小不能被24分割,则位块可以在文件末尾添加一些字节

,否则

创建的文件再次与原始文件相同。


那么你的问题是什么?


-

Karl Heinz Buchegger
kb ****** @ gascad.at


" Karl Heinz Buchegger < KB ****** @ gascad.at>在消息中写道

新闻:3F *************** @ gascad.at ......

Aehm。你可能没有正确表达自己。但是以16位块读取文件并以8位块写入读取数据
应该生成完全相同的文件。
以24位块写入可以在末尾添加一些字节。文件
如果原始文件大小不能被24分割,但是否则
创建的文件再次与原始文件相同。

那么你的问题是什么?
- -
Karl Heinz Buchegger
kb******@gascad.at



嗯,我可能太矮了。我的意思是构建一个通过16位块读取

文件的管道,进行一些编码,然后写回另一个文件

可变长度块(8,16)和24位)。当然有编码,但

我知道怎么做。我正在寻找的是性能最好且优雅的方式来实现以下约束:


1.它应该适用于任何平台

2.它适用于Little和Big Endian

3.它应该是int-size独立


有很多方法可以用C ++,cin / cout读取/写入文件,其中包括

重新定位,iostreams,文件打开/关闭等等其他。太多。那是'

为什么我要求一些大师给我看,可怜的凡人,光明。 ;-)


DdJ


Dario de Judicibus写道:

嗯,我可能也是短。我的意思是构建一个通过16位块读取
文件的管道,进行一些编码,然后写回另一个文件
可变长度块(8,16和24位)。当然有编码,但我知道该怎么做。我正在寻找的是具有以下约束的最佳表现和优雅的方式:

1.它应该适用于任何平台
2.它应该适用于Little和Big Endian
3.它应该是int-size独立

有很多方法可以用C ++,cin / cout读取/写入文件,包括
重新复制,iostreams,文件打开/关闭等等。太多。那就是为什么我要求一些大师给我看,可怜的凡人,光明。 ;-)

DdJ




可能最便携的方法是将数据读入输入区域,

应用字节序,应用编码,输入输出区域。


最有效的方法是将大块读入输入区域,

处理数据然后扔进输出区域。当读取大量的
块时,只需将它们设为16位的倍数即可。由于您保持流的流动,因此这种方法更有效。许多流

有一个加速的流。时间,对于较大的

数据块最小化。这种方法允许将过程分成三个
的同步任务:输入,处理,输出。


-

Thomas Matthews


C ++新闻组欢迎辞:
http://www.slack.net/~shiva/welcome.txt

C ++常见问题: http://www.parashift.com/c++-faq-lite

C常见问题: http://www.eskimo.com/~scs/c- faq / top.html

alt.comp.lang.learn.c-c ++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html

其他网站:
http://www.josuttis.com - C ++ STL图书馆书籍


I need to read a file as BINARY by 16 bits units, and write to another file
as BINARY by 8, 16 and 24 bits units. It is pratically a pipe. I''m looking
for a sample of C++ code simple, performing and portable. Possibly elegant
;-)))))) Thank you in advance.

Dario de Judicibus

解决方案



Dario de Judicibus wrote:


I need to read a file as BINARY by 16 bits units, and write to another file
as BINARY by 8, 16 and 24 bits units. It is pratically a pipe. I''m looking
for a sample of C++ code simple, performing and portable. Possibly elegant
;-)))))) Thank you in advance.



Aehm. You may not have expressed yourself correctly. But reading
a file in 16 bit chunks and writing the read data in 8 bit chunks
should produce the exact same file.
Writing in 24 bit chunks can add some bytes to the end of the file
if the original filesize is not divisable by 24, but otherwise
the created file is again identical to the original.

So what is your problem ?

--
Karl Heinz Buchegger
kb******@gascad.at


"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:3F***************@gascad.at...

Aehm. You may not have expressed yourself correctly. But reading
a file in 16 bit chunks and writing the read data in 8 bit chunks
should produce the exact same file.
Writing in 24 bit chunks can add some bytes to the end of the file
if the original filesize is not divisable by 24, but otherwise
the created file is again identical to the original.

So what is your problem ?
--
Karl Heinz Buchegger
kb******@gascad.at



Well, I was probably too short. What I meant is to build a pipe that reads a
file by 16 bit chunks, do some encoding, and writes back to another file
variable length chunks (8, 16 and 24 bits). Of course there is encoding, but
I know how to do it. What I was looking for is the most performing and
elegant way to do it with the following constraint:

1. it should work on any platform
2. it should work for Little and Big Endian
3. it should be "int-size" independent

There are a lot of ways to read/write files in C++, cin/cout with
rederection, iostreams, file open/close, and many others. Too many. That''s
why I ask some guru to show me, poor mortal, the light. ;-)

DdJ


Dario de Judicibus wrote:

Well, I was probably too short. What I meant is to build a pipe that reads a
file by 16 bit chunks, do some encoding, and writes back to another file
variable length chunks (8, 16 and 24 bits). Of course there is encoding, but
I know how to do it. What I was looking for is the most performing and
elegant way to do it with the following constraint:

1. it should work on any platform
2. it should work for Little and Big Endian
3. it should be "int-size" independent

There are a lot of ways to read/write files in C++, cin/cout with
rederection, iostreams, file open/close, and many others. Too many. That''s
why I ask some guru to show me, poor mortal, the light. ;-)

DdJ



Probably the most portable method is to read data into an input area,
apply endianism, apply encoding, throw into an output area.

The most efficient method is to read a large chunk into an input area,
process the data then throw into an output area. When reading large
chunks, just make them multiples of 16-bits. This method is more
efficient since you are keeping the stream flowing. Many streams
have a "ramp-up" time, which is minimalized for larger chunks of
data. This method allows the process to be split into three
asychronous tasks: input, process, output.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book


这篇关于管道:文件(16位)到FILRE(8,16,24bits)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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