linux字数统计小程序,一个统计文件字数的小程序

#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;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值