Last active
February 13, 2016 20:02
-
-
Save ninjapanzer/aa9cdd6f0d6a34d1f0df to your computer and use it in GitHub Desktop.
Use pointers to alias std::cin and std::cout
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
| #include <iostream> | |
| int main() { | |
| // Create a std::istream pointer and assign it where cin is bound | |
| std::istream *in; | |
| in = &std::cin; | |
| // Create a std::ostream pointer and assign it where cout is bound | |
| std::ostream *out; | |
| out = &std::cout; | |
| std::string word; | |
| // Dereference the pointer to access the original variable | |
| *in >> word; | |
| *out << word; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment