no match for ‘operator=’ (operand types are ‘std::basic_ostream’ and ‘int’)
#include <iostream>
int main() {
int x = 42;
std::cout = x;
return 0;
}
Explanation:
- Include the necessary header file for input/output operations (
#include <iostream>
). - Define the
main
function. - Declare an integer variable
x
and initialize it with the value42
. - Attempt to assign the value of
x
to thestd::cout
stream using the=
operator. - Note that there is an error in the assignment because the
std::cout
is an instance ofstd::basic_ostream
(output stream), and the=
operator is not defined for this type and theint
type. - This results in the compilation error: "no match for ‘operator=’ (operand types are ‘std::basic_ostream’ and ‘int’)."