怎样统计一个文件中所有字符串的个数(C语言)

谢谢

#include <iostream>
#include<fstream>
#include<vector>
using namespace std;
void main()
{
vector<char>test;
int i=0,count=1,count1=0;
fstream openfile("d:\\程序\\练习专用\\hello.txt");
if(!openfile)
{
cout<<"open failed!"<<endl;
exit(1);
}
do{
test.push_back(openfile.get());
count1++;
if(test[i]==' ')
count++;
if(openfile.eof())
break;
i++;
}while(!openfile.eof());
cout<<"the acount of the string is:"<<count<<endl;
cout<<"all of them are show below:"<<endl;
for(i=0;i<count1;i++)
cout<<test[i];
cout<<endl;

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-03-25
我说下思路吧
想 打开该文件
使用getc函数读取文件中的每一个字符 赋给 数组array[n]
知道feof函数返回值为1时
最后输出 数组的个数就可以了
第2个回答  2009-03-25
我有一个程序,给我80 分我就给你,一分都不能少了
相似回答