Cool way to read data in C++

Revision en1, by ivan100sic, 2022-04-22 16:35:02

I'll just leave this here:

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

struct _in {
    template<class T> operator T() {
        T x;
        cin >> x;
        return x;
    }
} in;

int main() {
    vector a(in, 0.0);
    for (auto& x : a) x = in;
    string s = in;
    cout << s << ' ' << a[2] << '\n';
}

Try with input

5
0.1 0.2 0.3 0.4 0.5
hello

Have a nice day

Tags c++20

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English ivan100sic 2022-04-22 16:35:02 459 Initial revision (published)