- #include "Dictionary.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- int main(int argc, char* argv[])
- {
- std::ifstream file("test.txt");
- std::ofstream out("test2.lzw");
- char ch;
- std::string perfix = "";
- Dictionary dict;
- while (!file.eof())
- {
- file>>ch;
- if (dict.is_exist(perfix+ch))
- {
- perfix += ch;
- }
- else
- {
- out<<dict.get_mask(perfix)<<ch;
- dict.add(perfix+ch);
- perfix = "";
- }
- }
- if (perfix != "")
- {
- out<<dict.get_mask(perfix);
- }
- file.close();
- out.close();
- std::cout<<"conpress success!"<<std::endl;
- return 0;
- }
lz78的压缩部分
最新推荐文章于 2023-09-02 01:38:03 发布
本文介绍了一种使用LZW压缩算法进行文件压缩的C++实现方法。通过读取原始文件并利用字典来记录字符串模式,该程序能够有效地将输入文件压缩并输出到新的文件中。文中展示了如何构建和更新字典、如何处理输入字符以及如何输出压缩后的结果。
1066

被折叠的 条评论
为什么被折叠?



