This program finds words and erases all of them that are repeated in the text file. Here, I wrote this code to do so by inputting a specific word, but I want the program to find the kind of words by itself and in the result will show only the unrepeated words. I have tried by best but have failed. Could you advise me to find a better way?
int main()
{
   ifstream fin("name.txt");
   ofstream fout("result.txt");
   string word;
   string line;
   int pos;
   int ccount=0;;
   cout<<"Please input word:";
   cin>>word;
   while(getline(fin,line))
   {
       pos= 0;
       while(line.find(word,pos)!=string::npos)
       {
               pos = line.find(word,pos);
               line.erase(pos,word.length());
       }
        fout<<line<<endl;
   }
    fin.close();
    fout.close();
}
 
     
    