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