tags:

views:

97

answers:

3
char b;

operator<<(cout,(operator>>(cin,b)));

this is not compiling in vc++ because all 8 overloads cant convert this type.

can any one explain this.....

is their a problem with return type...........

+7  A: 

The stream extraction operation i.e. op>> returns an object of type istream&. The op<< does not have an overload which takes istream& as its second parameter. You need to split the two actions or define one such overload.

dirkgently
A: 

char b; operator<<(cout,(operator>>(cin,b),b));

k_zaur_k
Spookily near identical to the code in the comment by David Rodriguez, posted 18 minutes earlier.
anon
Nice one. Another interpretation of OP's code: `cout.operator<<(operator>>(cin, b))`. That would print the address of cin, though (result of conversion to `void*`).
visitor
A: 

The problem is that the output operator that would work takes a void*, but that is a member. If you change it to the following, it will convert the istream& returned by the operator>> to void* and output it (and it is a null pointer if the extraction worked, and a non-NULL pointer otherwise):

cout.operator<<(operator>>(cin,b));

I'm not quite sure though why you are doing this. Can you please elaborate? If you want to output all stuff from cin right away, use the underlying buffer

cout << cin.rdbuf();
Johannes Schaub - litb