C++面向对象程序设计 031:山寨版istream_iterator ---- (北大Mooc)
发布日期:2021-06-30 22:27:49 浏览次数:2 分类:技术文章

本文共 950 字,大约阅读时间需要 3 分钟。

文章目录


原题题目

在这里插入图片描述

#include 
#include
using namespace std;template
class CMyistream_iterator{
// 在此处补充你的代码};int main() {
int t; cin >> t; while( t -- ) {
CMyistream_iterator
inputInt(cin); int n1,n2,n3; n1 = * inputInt; //读入 n1 int tmp = * inputInt; cout << tmp << endl; inputInt ++; n2 = * inputInt; //读入 n2 inputInt ++; n3 = * inputInt; //读入 n3 cout << n1 << " " << n2<< " " << n3 << " "; CMyistream_iterator
inputStr(cin); string s1,s2; s1 = * inputStr; inputStr ++; s2 = * inputStr; cout << s1 << " " << s2 << endl; } return 0; }

代码实现

private:    T ret;    bool read;public:    CMyistream_iterator(istream & a){
read = false;} T operator*() {
if(!read) {
cin>>ret; read = true; } return ret; } void operator++(int n) {
read = false; }

转载地址:https://love6.blog.csdn.net/article/details/115007429 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:C++面向对象程序设计 032:这个模板并不难 ---- (北大Mooc)
下一篇:Python课后作业 4. 绩点计算 ---- (第三次作业)

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年04月30日 09时35分13秒