使用 C++ 进行文件压缩

发布于 2024-10-30 07:58:32 字数 244 浏览 2 评论 0原文

我想制作自己的文本文件压缩程序。我对 C++ 编程了解不多,但我已经学习了所有基础知识以及写入/读取文件。 我在 google 上搜索了很多有关压缩的信息,并看到了许多不同类型的压缩文件的方法,例如 LZW 和 Huffman。问题是大多数都没有源代码,或者有非常复杂的源代码。 我想问一下大家有没有什么好的网页可以让我自己学习和制作压缩程序?

编辑: 我会让这个话题再开放一会儿,因为我打算在接下来的几天里研究这个,如果我有任何问题,我会在这里问他们。

I want to make my own text file compression program. I don't know much about C++ programming, but I have learned all the basics and writing/reading a file.
I have searched on google a lot about compression, and saw many different kind of methods to compress a file like LZW and Huffman. The problem is that most of them don't have a source code, or they have a very complicated one.
I want to ask if you know any good webpages where I can learn and make a compression program myself?

EDIT:
I will let this topic be open for a little longer, since I plan to study this the next few days, and if I have any questions, I'll ask them here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

眼眸 2024-11-06 07:58:32

大多数算法都非常复杂。但它们都有一个共同点,那就是它们都获取重复的数据,并且只存储一次,并且有一个知道如何解压缩它们的系统(将重复的段放回原位)

这是一个您可以尝试实现的简单示例。

我们有这个数据文件

XXXXFGGGJJ

DDDDDDDDAA

XXXXFGGGJJ

这里有重复的字符和重复的两行。因此,您可以从寻找减少文件大小的方法开始。

这是一个简单的压缩算法。

4XF3G2J

8D2A

4XF3G2J

所以我们有 4 个 X、1 个 F、3 个 G 等等。

Most of the algorithms are pretty complex. But they all have in common that they are taking data that is repeating and only store it once and have a system of knowing how to uncompress them (putting the repeated segments back in place)

Here is a simple example you can try to implement.

We have this data file

XXXXFGGGJJ

DDDDDDDDAA

XXXXFGGGJJ

Here we have chars that repeat and two lines that repeat. So you could start with finding a way to reduce the filesize.

Here's a simple compression algorithm.

4XF3G2J

8D2A

4XF3G2J

So we have 4 of X, one of F, 3 of G etc.

写下不归期 2024-11-06 07:58:32

您可以尝试这个页面,它包含清晰的基础知识演练压缩和首要原则。

You can try this page it contains a clear walk through of the basics of compression and the first principles.

无畏 2024-11-06 07:58:32

压缩并不是最容易的任务。我参加了大学课程学习 LZW 和 Huffman 等压缩算法,我可以告诉你它们并不那么容易。如果 C++ 是您的第一语言并且您刚刚开始接触此类事情,那么我不建议您尝试编写自己的排序算法。如果您更有经验,那么我会尝试编写源代码而不向您提供任何代码 - 这表明您真正了解压缩算法。

这就是我的教学方式——教授用非常广泛的术语解释了算法,然后我们要么实现它(请注意,用 Java),要么回答有关算法在某些情况下如何表现的问题。如果我们能做到其中任何一个,那么我们就真正了解了该算法 - 无需他向我们展示任何来源 - 这是一项值得开发的好技能;)

Compression is not the most easy task. I took a college class to learn about compression algorithms like LZW and Huffman, and I can tell you that they're not that easy. If C++ is your first language and you're just starting into this sort of thing, I wouldn't recommend trying to write your own sorting algorithm just yet. If you are more experienced, then I would try writing source without any code being provided to you - this shows that you truly understand the compression algorithm.

This is how I was taught - the professor explained the algorithm in very broad terms, and then either we would implement it (in Java, mind you) or we would answer questions about how the algorithm would behave under certain circumstances. If we could do either of those, then we really knew the algorithm - without him showing us any source at all - it's a good skill to develop ;)

还不是爱你 2024-11-06 07:58:32

霍夫曼编码树并不太复杂,我将从它们开始。这是一个链接:示例:霍夫曼编码树

Huffman encoding tree's are not too complicated, I'd start with them. Here's a link: Example: Huffman Encoding Trees

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文