C++ Format for cout << Automatically -
if had simple class 2 variables, x , y, , function tostring() returns formatted string data. when call
cout << simpleclass << "\n";
anyone know way have simpleclass.tostring automatically called return correctly formatted string? i'm guessing there's way operator functions, don't know how this.
if you're asking how define such operator,
template<class chart, class traitst> std::basic_ostream<chart, traitst>& operator <<(std::basic_ostream<chart, traitst>& os, simpleclass const& sc) { return os << sc.tostring(); }
Comments
Post a Comment