hello,
how do i remove elements which are repeated in a list .I cant seem to do it . in this program i am first putting elements into the list ,then searching for a particular element seeing how many times it occurs in the list(count) .i need to display the word and the count . but i need to eliminate the alias words in the list .am so confused that now i cant even trace the program . pls help !!!!!!!!!!!!!
#include<iostream>
#include<conio.h>
#include<fstream>
#include<list>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
//void fi(int count,string word);
int cnt;
string key;
string word;
char line[80];
char line1[80];
list<string> lst;
list<string>::iterator p;
string word1;
int n;
map<string,int> m;
ifstream in ("d:/programming/count.txt");
if(!in)
{
cout<<"cannot open count"<<endl;
}
ofstream out ("d:/programming/count1.txt");
if(!out)
{
cout<<"cannot open count1"<<endl;
}
do{
in.getline(line,80);
word=line;
lst.push_back(word);
}while(in);
p=lst.begin();
while(p != lst.end())
{
lst.sort();//sort the list
out<<*p<< " " << endl;//put the contents into the final file
p++;
}
ifstream in1 ("d:/programming/count.txt");
if(!in1)
{
cout<<"cannot open count"<<endl;
}
ofstream out1 ("d:/programming/count.txt");
if(!out1)
{
cout<<"cannot open count1"<<endl;
}
cout<<"do it"<<endl;
do{
in1.getline(line,80);
word=line;
out1<<word<<endl ;
cnt=count(lst.begin(),lst.end(),word);
out1<<cnt;
for(cnt;cnt>1;cnt--)
{
lst.pop_front();
}
}while(in1);
getch();
return 0;
}
/*void fi(int count,string word)
{
char line[80];
list<string> lst;
ifstream in2 ("d:/programming/count1.txt");
if(!in2)
{
cout<<"cannot open count"<<endl;
}
do{
in2.getline(line,80);
word=line;
cout<<"sec "<<word<<endl;
lst.push_back(word);
}while(in2);
list<string>::iterator p;
p=find(lst.begin(),lst.end(),word);
for(int i=count ; i<2;i--)
{
lst.pop_front();
cout<<count<<endl;
}
while(p != lst.end())
{
cout<<*p<< " " << endl;//put the contents into the final file
p++;
}
}*/