perilbrain
perilbrain

Reputation: 8197

operator inside operator not working

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...........

Upvotes: 0

Views: 253

Answers (3)

k_zaur_k
k_zaur_k

Reputation: 400

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

Upvotes: 0

Johannes Schaub - litb
Johannes Schaub - litb

Reputation: 506925

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();

Upvotes: 0

dirkgently
dirkgently

Reputation: 111130

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.

Upvotes: 6

Related Questions