031 山寨版istream_iterator

#include <iostream>
#include <string>

using namespace std;
template <class T>
class CMyistream_iterator
{

    // 在此处补充你的代码
public:
    T a;

    CMyistream_iterator(istream& cin){
        cin >> a;
    }

    operator T *() {
        return &a;
    }

      CMyistream_iterator & operator++(int ab) { //右侧++需要传无用int 类型参数
        cin >> a;
        return * this;
    }

};



int main()
{
    int t;
    cin >> t;
    while (t--) {
        CMyistream_iterator<int> 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<string> inputStr(cin);
        string s1, s2;
        s1 = *inputStr;
        inputStr++;
        s2 = *inputStr;
        cout << s1 << " " << s2 << endl;
    }
    return 0;
}

posted @ 2022-02-24 11:56  icefield817  阅读(95)  评论(0编辑  收藏  举报