#ifndef WORD_COUNT_H_INCLUDED
#define WORD_COUNT_H_INCLUDED
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class word_count
{
private:
vector all_lines;
vector all_words;
void delete_same_words();
void get_all_lines(char *s);
void get_all_words();
public:
void get_allwords(int n,char *s);
};
bool GT6(const string hs)
{
return hs.size()>6;
}
bool my_com(const string & lhs,const string &rhs)
{
return lhs.size()
}
void word_count::get_all_lines(char *s)
{
ifstream inf(s);
string str;
while(getline(inf,str))
{
all_lines.push_back(str);
}
inf.close();
}
void word_count::get_all_words()
{
string str;
int all_lines_size=all_lines.size();
for(int i=0;i
{
istringstream inf(all_lines[i]);
while(inf>>str)
all_words.push_back(str);
}
}
void word_count::get_allwords(int n,char *s)
{
this->get_all_lines(s);
this->get_all_words();
vector::iterator it_end=unique(all_words.begin(),all_words.end());
all_words.erase(it_end,all_words.end());
stable_sort(all_words.begin(),all_words.end(),my_com);
int total_num=0;
/*
for(vector::iterator it=all_words.begin();it != all_words.end();it++)
{
if(it->size() > 6)
{
cout<
}
}
*/
for(vector::iterator it=all_words.begin();it != all_words.end();it++)
{
it=find_if(it,all_words.end(),GT6);
cout<
total_num++;
}
cout< 6 is :"<
}
#endif // WORD_COUNT_H_INCLUDED
#include
#include "word_count.h"
using namespace std;
int main()
{
word_count wc;
char *s="text.txt";
wc.get_allwords(6,s);
return 0;
}