Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overloading << operator ostream [closed]

Why doesn't the line below work?

#include <iostream>

std::ostream& operator <<( std::ostream& os, const char *c)
{
    os << c; // why does this line doesn't work?
    return os;
}

int main()
{
    const char *c = "Hi";
    std::cout << c;
}
like image 692
user33424 Avatar asked Jun 01 '26 12:06

user33424


1 Answers

The problem is std::ostream& operator <<( std::ostream& os, const char *c) has already been overloaded in iostream.

like image 53
shreyasva Avatar answered Jun 03 '26 01:06

shreyasva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!