统计单词总数c++程序

/*编写一个程序,用于统计文件中单词的总数,不同单词的数目。(假设输入文件中只包含字母和空格)*/
#include
#include
#include
using namespace std;

class Record
{
public:
string word;
int count;

Record(){word = " ";count = 0;}
};

void main()
{
Record *p = new Record[100];
Record *p1 = p;
string input;
int total = 0;
int dif_total = 0;

fstream fout("text.txt");
while(!fout.eof())
{
fout>>input;
Record *cmp = p;
for(;cmp < p1;cmp++)
{
if(cmp->word == input)
{
cmp->count ++;
total ++;
break;
}
}
if(cmp>=p1)
{
p1 -> word = input;
p1->count ++;
p1 = p1 + 1;
total ++;
dif_total ++;
}
}

cout<<"The number of the words is:"<cout<<"The number of the diffrent words is:"<}

相关文档
最新文档