This question already has an answer here:
- Conditional operator used in cout statement 2 answers
I have the following test program:
#include <string>
#include <iostream>
int main()
{
std::string s;
std::string a = "sd";
std::cout << a==s ? "y" : "n";
return 0;
}
Trying to compile this with g++ test.cpp
gives the following cryptic error:
error: no match for 'operator==' (operand types are 'std::basic_ostream<char>' and 'std::string {aka std::basic_string<char>}')
std::cout << a==s ? "y" : "n";
^
It seems that s
is being correctly compiled as type std::string
, while a
is being compiled as std::basic_ostream<char>
!? HELP!!