帮忙调试一下

来源:百度知道 编辑:UC知道 时间:2024/09/23 12:08:05
#include<iostream>
#include<fstream>
#include <stdlib.h>
#include<string.h>

using namespace std;

int main()
{
char word;
cin>>word;
int i=0;
ifstream fin("text1.txt");
// cout<<"the contents of the file:\n\n";
char ch;
while(fin.get(ch))
{
cout<<ch<<endl;
int result=strcmp(ch,word);
if(result==0)
{
i++;
}

}
cout<<"i: "<<i<<endl;
return 0;
}
int result=strcmp(ch,word);
这句话怎么改正确

//是统计文件中单个字符出现的次数吧

#include<iostream>
#include<fstream>
#include <stdlib.h>
#include<string.h>

using namespace std;

int main()
{
char word;
cin>>word;
int i=0;
ifstream fin("text1.txt");
// cout<<"the contents of the file:\n\n";
char ch;
while(fin.get(ch))
{
cout<<ch<<endl;
if(ch==word) //单个字符比较不用strcmp(ch,word),那是字符串的比较。
{
i++;
}

}
cout<<"i: "<<i<<endl;
return 0;
}

想完成什么功能啊?
读代码很累的,给两句说明啊,
重点调试哪里,疑问在哪里?