C++ //练习 14.12 你在7.5.1节的练习7.40(第261页)中曾经选择并编写了一个类,为它定义一个输入运算符并确保该运算符可以处理输入错误。

C++ Primer(第5版) 练习 14.12

练习 14.12 你在7.5.1节的练习7.40(第261页)中曾经选择并编写了一个类,为它定义一个输入运算符并确保该运算符可以处理输入错误。

环境:Linux Ubuntu(云服务器)
工具:vim
代码块
cpp 复制代码
class Date{
	public:
	Date();
	Date(size_t y, size_t m, size_t d): year(y), month(m), day(d) {}
	friend ostream &operator<<(ostream &, Date &);
	friend istream &operator>>(istream &, Date &);

	private:
	size_t year;
	size_t month;
	size_t day;
};

ostream &operator<< (ostream &output, Date &d){
	output<<d.year<<"-"<<d.month<<"-"<<d.day<<endl;
	return output;
}

istream &operator>> (istream &input, Date &d){
	input>>d.year>>d.month>>d.day;
	if(!input){
		d = Date(0, 0, 0);
	}
	return input;
}
相关推荐
meiying883811 分钟前
快递单号批量查询Python脚本:从手动到自动化的完整实现
开发语言·python·自动化
@大迁世界1 小时前
告别 Go,拥抱 Rust
开发语言·golang·rust
SEO_juper1 小时前
Node.js 重定向链检测工具:301 跳了几跳、有没有成环,一次看清
xml·开发语言·python·node.js·json·bash
学逆向的1 小时前
C 指针常量与常量指针
c语言·开发语言·网络安全
小郎君6582 小时前
Vue keep-alive 切标签后滚动位置回顶?因为 onDeactivated 里读到的 scrollTop 是 0
算法
低调滴开发2 小时前
3 行代码写崩一个函数?切片才是 Rust 字符串处理的正确姿势
开发语言·后端·rust
CodeYp20192 小时前
第15讲:二叉搜索树
开发语言·c++·二叉搜索树
邵奈一2 小时前
GPT-6.1 Terra速度是Sol的3倍,价格减半
算法
RaaS1002 小时前
Node.js Brotli RCE 漏洞自查指南:fetch、undici、axios 都在影响面,三分钟确认你的版本
人工智能·深度学习·算法
猫猫.1532 小时前
HashTable、HashMap、ConcurrentHashMap 核心区别总结
java·开发语言·java-ee