向专家提问!!!文件之困扰!

giant7 2009-01-02 01:36:23
。。。。。。。。。。代码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可以准确进行,为什么用文件输入输出以后就不能执行?????
请教各位!!!!!!
...全文
165 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wiowei 2009-01-02
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 ggxxkkll 的回复:]
array是存放字符的数组,为什么在调试跟踪时:代码1中的循环中的判断语句:if(array[m].ch==p->ch) 没有执行过,
文件到底把我的代码怎么了???
[/Quote]
那还不好办:
for(int m=0;m <count;m++) //加断点,看count值
{
huffnode *p=head->next;
while(p) //加断点,看p值
{
if(array[m].ch==p->ch)

看为何进入不了while呗
giant7 2009-01-02
  • 打赏
  • 举报
回复
array是存放字符的数组,为什么在调试跟踪时:代码1中的循环中的判断语句:if(array[m].ch==p->ch) 没有执行过,
文件到底把我的代码怎么了???
wiowei 2009-01-02
  • 打赏
  • 举报
回复
编译时出现了:代码1中的循环中的判断语句:if(array[m].ch==p->ch) 不能正常执行:

array是什么?
星羽 2009-01-02
  • 打赏
  • 举报
回复
调整跟踪一下,你那些文件输出语句 put 什么的有没有被调用
星羽 2009-01-02
  • 打赏
  • 举报
回复
代码1 的文件有没有输出任何东西?
giant7 2009-01-02
  • 打赏
  • 举报
回复
成功了,
编译没任何错误,
xiaoyisnail 2009-01-02
  • 打赏
  • 举报
回复
ofstream outfile2("file2.txt");
这句有没有成功?

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧