An Interesting, Not though Important Finding

Revision en5, by salehin_076923, 2025-05-21 22:15:18

In C++, for output, we usually write cout<<x;

But if we want to write in reverse-> x>>cout;

Same case for cin. Instead of cin>>x, if we want to write x>>cin.

We can do it in class.

#include<bits/stdc++.h>
using namespace std;

class number{
    int x;
public:
    number(){}
    number(int x):x(x){};
    istream& operator>>(istream& in){
        cin>>x;
        return in;
    }
    ostream& operator<<(ostream& out){
        cout<<x;
        return out;
    }
};

int main(){
    number n;
    n>>cin;
    n<<cout;
    return 0;
}
Tags code, c++

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en5 English salehin_076923 2025-05-21 22:15:18 67 (published)
en4 English salehin_076923 2025-05-21 22:13:50 56
en3 English salehin_076923 2025-05-21 22:12:37 67
en2 English salehin_076923 2025-05-21 22:10:39 2 Tiny change: 'n class.\n```c++\n' -> 'n class.\n\n```c++\n'
en1 English salehin_076923 2025-05-21 22:08:38 646 Initial revision (saved to drafts)