New course! Every coder should learn Generative AI!
Try a free lesson0
In c++, int a=5,b=2,c; cout<<c=(a%b); show error why someone help me.??
2 Answers
+ 3
/Playground/file0.cpp: In function 'int main(0:
/Playground/file0.cpp:6:13: error: no
match for 'operator= (operand types are
'std::basic_ostream<char>' and 'int)
6 cout<<c=(a%b);
This happens because C++ can't find a matching operator = overload in template class std::basic_ostream
The = operator in the expression `c = ( a % b )` is the culprit.
If you want, you can wrap the whole expression inside parentheses like
std::cout << ( c = ( a % b ) ).
This way the whole expression `( c = ( a % b ) )` will be evaluated first, and only the evaluation result (1) will be inserted into the output stream, std::cout
+ 1
Thank you.