读入一段英文输出每个单词出现次数
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
ifstream is("C:/Users/25776/Desktop/311.txt");
string temp;
getline(is, temp);
string x[100];
int count = 0;
while (temp.find(" ") != temp.npos)
{
count++;
x[count] = temp.substr(0, temp.find(" "));
temp.erase(0, temp.find(" ") + 1);
}
for (int i = 1; i <= count; i++)
{
int n = 0;
int flag = 0;
for (int j = 1; j < i; j++)
{
if (x[i] == x[j])
flag = 1;
}
for (int j = i; j <= count; j++)
{
if (x[i] == x[j])
n++;
}
if (flag == 0)
cout << x[i] <<"出现"<< n<<"次" << endl;
}
}