怎样统计一个文件中所有字符串的个数(C语言)
来源:百度知道 编辑:UC知道 时间:2024/06/01 10:50:04
谢谢
#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;
}
我有一个程序,给我80 分我就给你,一分都不能少了
我说下思路吧
想 打开该文件
使用getc函数读取文件中的每一个字符 赋给 数组array[n]
知道feof函数返回值为1时
最后输出 数组的个数就可以了