Last active
April 19, 2019 06:28
-
-
Save iamazeem/2f352990ac8b2b9bcac40a1db9490886 to your computer and use it in GitHub Desktop.
C++: std::istream_iterator example (https://stackoverflow.com/a/51889159/7670262)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://stackoverflow.com/a/51889159/7670262 | |
| #include <iterator> | |
| #include <iostream> | |
| struct data | |
| { | |
| data() = default; | |
| int num1 = 0; | |
| int num2 = 0; | |
| friend std::istream& operator>>( std::istream& is, data& d ) | |
| { | |
| is >> d.num1 >> d.num2; | |
| return is; | |
| } | |
| friend std::ostream& operator<<( std::ostream& os, const data& d ) | |
| { | |
| os << "[" << d.num1 << ", " << d.num2 << "]"; | |
| return os; | |
| } | |
| }; | |
| int main() | |
| { | |
| std::istream_iterator<data> din(std::cin); | |
| data daData = *din; | |
| std::cout << daData; | |
| return 0; | |
| } | |
| /* | |
| INPUT: | |
| 1 2 | |
| OUTPUT: | |
| [1, 2] | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment