Beginner question about getting reference to cin

Posted by John C on Stack Overflow See other posts from Stack Overflow or by John C
Published on 2010-05-31T16:32:14Z Indexed on 2010/05/31 16:43 UTC
Read the original article Hit count: 161

Filed under:

I'm having problems wrapping my head around this. I have a function

void foo(istream& input) {
     input = cin;
}

This fails (I'm assuming because cin isn't supposed to be "copyable".

however, this works

void foo(istream& input) {
    istream& baz = cin;
}

Is there a reason that I can get a reference to cin in baz but I cannot assign it to input?

Thanks

© Stack Overflow or respective owner

Related posts about c++