I am trying to define operator + for string and double using the following function
string operator + (const double& b,const string a){
return to_string(b)+a;
}
When I am doing the following operation, it works well
double c = 100.256;
string d = "if only";
cout<<c+d<<"\n";
but when i pass const char instead of string , it throws compilation error(invalid operands of types ‘double’ and ‘const char [4]’ to binary ‘operator+’)
double c = 100.256;
string test = c+"sff";
Why is implicit conversion of const char[] "sff" to string not happening?
const char *tostd::string. The good answer would be why it cannot be used here.std::string operator+(const double b, std::string_view a) { return std::to_string(b) + std::string(a); } std::string test = c + "sff"s;