简单的问题,请进!
下面我编的一个统计文本行数,单词数,字母数的程序,但只可以统计英文,如果想统计汉字,怎么办?
能否详细解释一下?
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
void main()
{
fstream f;
f.open("10.txt",ios::out|ios::in);
if(!f)
{
cout<<"can not open the file ,L am sorry!"<<endl;
abort();
}
char ch;
int i=0;
int j=0;
int k=0;
while(f.get(ch))
{
if(ch=='\n')
{
i++;
continue;
}
if(ch==' ')
{
j++;
continue;
}
else
k++;
}
cout<<"hang shu is"<<i+1<<endl;
cout<<"dang ci shu is"<<(j+i)<<endl;
cout<<"zhi mu shu is": "<<k+1<<endl;
}