I know it seems too much Java or C#. However, is it possible/good/wise to make my own class valid as an input for the function std::to_string
?
Example:
<
You probably just want to overload operator<<()
something like:
std::ostream& operator << ( std::ostream& os, const my_class& rhs ) {
os << "I am " << rhs.i;
return os;
}
Alternatively:
std::ostream& operator << ( std::ostream& os, const my_class& rhs ) {
os << rhs.print_a_string();
return os;
}
Then you can simply do:
int main() {
my_class my_object;
std::cout << my_object;
return 0;
}