C++面向对象程序设计 031:山寨版istream_iterator ---- (北大Mooc)

文章目录

    • 原题题目
    • 代码实现


原题题目

在这里插入图片描述

#include 
#include using namespace std;
template <class T>
class CMyistream_iterator
{
// 在此处补充你的代码
};int main()  
{ int t;cin >> t;while( t -- ) {CMyistream_iterator<int> inputInt(cin);int n1,n2,n3;n1 = * inputInt; //读入 n1int tmp = * inputInt;cout << tmp << endl;inputInt ++;   n2 = * inputInt; //读入 n2inputInt ++;n3 = * inputInt; //读入 n3cout << n1 << " " << n2<< " " << n3 << " ";CMyistream_iterator<string> 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;}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部