d_state.h
来自「数据结构c++语言描述stl版 威廉兄弟的好书,值得看,这是配书代码」· C头文件 代码 · 共 43 行
H
43 行
#ifndef STATECITY_CLASS
#define STATECITY_CLASS
#include <iostream>
#include <string>
using namespace std;
// object stores the state name and city in the state
class stateCity
{
public:
stateCity (const string& name = "", const string& city = ""):
stateName(name), cityName(city)
{}
// output the state and city name in the format
// cityName, stateName
friend ostream& operator<< (ostream& ostr, const stateCity& state)
{
ostr << state.cityName << ", " << state.stateName;
return ostr;
}
// operators < and == must be defined to use with set object.
// operators use only the stateName as the key
friend bool operator< (const stateCity& a, const stateCity& b)
{
return a.stateName < b.stateName;
}
friend bool operator== (const stateCity& a, const stateCity& b)
{
return a.stateName == b.stateName;
}
private:
string stateName, cityName;
};
#endif // STATECITY_CLASS
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?