#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
class wordtype
{
char word[20];
int count;
};
int getwords(wordtype *w)
{
ifstream in("words.text");
int n,m = 0;
char word[20];
while(in)
{
in >> word;
if(!in) break;
bool flag = 0;
for(;m < n;m ++)
{
if(!strcmp(word,word[m].word))
{
words[m].count ++;
flag = true;
break;
}
}
if(!flag)
{
words[m].count = 1;
strcpy(words[m].word,word);
n ++;
}
}
return n;
}
int main(int argc, char const *argv[])
{
wordtype words[100] = {"",0};
int n = getwords(words);
cout << "Result:" << endl;
for(int m = 0; m < n ; m ++)
{
cout << words[m].word << ':' << words[m].count << endl;
}
cout << "Totally:" << n << endl;
return 0;
}
c++标准输入输出流(四)
最新推荐文章于 2022-11-10 19:00:56 发布