Here is my simple code:
#include <iostream> int main() { int foo; std::cin.rdbuf(std::cout.rdbuf()); std::cin>>foo; // what'll happen at this line? whatever I'll input will go to cout buffer then to foo , right? }
What I thought about the above code would set the cin buffer in the cout buffer, so when I enter some number, it will also be output. I guess I'm confused by my program. Can someone tell me what is going on in the program?
Also, if I add another line to the end: std::cout<<foo; then it prints a random number, which means that foo is never entered. So what is going on as a whole?
source share