myclass is a C++ class written by me and when I write:
myclass
myclass x; cout << x;
How do I output 10 or 20.2, like an integer or a float value?
10
20.2
integer
float
Typically by overloading operator<< for your class:
operator<<
struct myclass { int i; }; std::ostream &operator<<(std::ostream &os, myclass const &m) { return os << m.i; } int main() { myclass x(10); std::cout << x; return 0; }
2.1m questions
2.1m answers
60 comments
57.0k users