- #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;
- }