📄 huff_main.cpp
字号:
#include<stdio.h>
#include<stdlib.h>
#include<fstream.h>
#include<iostream.h>
#include"huff_header.h"
void Get_weight(void)
{char ch;
int s[129]={0};
int intch;
fstream Password_file;
fstream infile;
infile.open("test.txt",ios::in|ios::out);
if(!infile)
printf("ERROR");
Password_file.open("Password.txt",ios::out|ios::binary);
if(!Password_file)
cout<<"ERROR";
infile.get(ch);
while(!infile.eof())
{intch=(int)ch;
if(intch<0||intch>128)
{infile.get(ch); continue;}
s[(int)ch+1]++;
infile.get(ch);
}
Password_file.clear();
Password_file.seekp(0L,ios::beg);
Password_file.write((char*)s,sizeof(s));
infile.close();
Password_file.close();
}
void main()
{
fstream infile,outfile,out2file,Password;
infile.open("test.txt",ios::in|ios::out);
if(!infile)
printf("ERROR");
outfile.open("out.txt",ios::out|ios::in);
if(!outfile)
cout<<"outfile error";
out2file.open("out2.txt",ios::out);
if(!out2file)
cout<<"outfile error";
Password.open("Password.txt",ios::in|ios::binary);
if(!Password)
cout<<"Password Error!";
HTree HT;
HuffCode HC;
int w[129];
//for(int m=0;m<=128;m++)
// w[m]=m;
Get_weight();
Password.clear();
Password.seekg(0L,ios::beg);
Password.read((char*)w,sizeof(w));
for(int index=0;index<=128;index++)
cout<<w[index]<<endl;
CreateHuffTree(HT,w,HC,128);
Huff_encoder(infile,outfile,HC,128);
Huff_decoder(outfile,out2file,HC,128,HT);
infile.close();
outfile.close();
out2file.close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -