List列表实现统计文档中单词出现的次数

WordFreq.h代码:

#include<iostream>
#include<string>
using namespace std;
class WordFreq
{
private:
	int m_freq;
	string word;
public:
	WordFreq(const string str):word(str),m_freq(1){}
	void Incream()
	{
		m_freq++;
	}
	friend bool operator==(WordFreq& st1,WordFreq& st2)
	{
		return st1.word==st2.word;
	}
	friend bool operator<(WordFreq& st1,WordFreq& st2)
	{
		return st1.word<st2.word;
	}
	friend ostream& operator<<(ostream& os,WordFreq &st1)
	{
		os<<st1.word <<"'s frequence is "<<st1.m_freq<<endl;
		return os;
	}
};


cpp:

#include<iostream>
#include<string>
using namespace std;
class WordFreq
{
private:
	int m_freq;
	string word;
public:
	WordFreq(const string str):word(str),m_freq(1){}
	void Incream()
	{
		m_freq++;
	}
	friend bool operator==(WordFreq& st1,WordFreq& st2)
	{
		return st1.word==st2.word;
	}
	friend bool operator<(WordFreq& st1,WordFreq& st2)
	{
		return st1.word<st2.word;
	}
	friend ostream& operator<<(ostream& os,WordFreq &st1)
	{
		os<<st1.word <<"'s frequence is "<<st1.m_freq<<endl;
		return os;
	}
};


 

阅读更多
文章标签: 文档 list string os
个人分类: STL
上一篇List模板类实现回文判断
下一篇利用栈实现整型多进制转换
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭