I have a Date class
class Date { int dd, mm, yyyy};
I have written the rule of 3, and all that works. I want to convert the Date into a string. Do I need a conversion operator string() to do so? thx!
std::ostream& operator<<(std::ostream& s, const Date& d)
{
s << "Format your date object here";
return s;
}
In C++ you use streams if you want toString() like functionality.
So for example you could do
s << mm << "/" << dd << "/" << yyyy;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With