Reputation: 27
I have this error message:
Error C2678 binary '^': no operator found which takes a left-hand
operand of type 'std::basic_ostream<char,std::char_traits<char>>'
(or there is no acceptable conversion)
with this code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << 2 ^ 4;
}
could you help me with this code, please
Upvotes: 1
Views: 81
Reputation: 3
Can you use this code.
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << (2 ^ 4);
return 0;
}
Upvotes: 0
Reputation: 172884
operator<<
has higher precedence than operator ^
, so cout << 2 ^ 4;
is interpreted as (cout << 2) ^ 4;
. (cout << 2)
returns cout
itself, which can't be used as operand of operator ^
.
Change the code to
cout << (2 ^ 4);
Upvotes: 4