向专家提问!!!文件之困扰!
。。。。。。。。。。代码1.。。。。。。。。
void hufftree::sortcode() //............输出编码信息
{ cout < <"编码后信息为:" < <endl;
ofstream outfile2("file2.txt");
if(!outfile2)
{cout < <"open file2.txt error!" < <endl;
exit(1);
}
for(int m=0;m <count;m++)
{
huffnode *p=head->next;
while(p)
{
if(array[m].ch==p->ch)
{
//cout < <"\nThe char " < <p->ch < <" 's huffman code is ";
for(int i=0;i <100;i++)
{
if(p->code[i]==0 || p->code[i]==1)
{
outfile2.put(p->code[i]);
}
}
}
p=p->next;
}
}
outfile2.close();
ifstream infile2("file2.txt",ios::in);
if(!infile2)
{cout < <"open file2.txt error!" < <endl;
exit(1);
}
ofstream outfile21("file21.txt");
if(!outfile21)
{
cout < <"open file21.txt" < <endl;
}
char c;
{if(!infile2)
{cout < <"open error!" < <endl;
}
while(infile2.get(c))
{outfile21.put(c);
cout < <c;}
}
infile2.close();
outfile21.close();
cout < <endl;
}
不用文件的相同程序代码:
。。。。。。。。。代码2.。。。。。。。。。。。
void outputcode()//-----------------------------------------------输出编码--------------------
{
huffnode *p=head->next;
int j(0);
while(p)
{
cout < <"\nThe char " < <p->ch < <" 's huffman code is ";
for(int i=0;i <100;i++)
{
if(p->code[i]==0 || p->code[i]==1)
{
cout < <p->code[i];
a[j]=p->code[i];
j++;
}
}
p=p->next;
}
maxsize=j;
}
为什么用文件后不能输出编码呢???
编译时出现了:代码1中的循环中的判断语句:if(array[m].ch==p->ch)
不能正常执行:
不知为什么,而代码2可以准确进行,为什么用文件输入输出以后就不能执行?????
请教各位!!!!!!