Typically by overloading operator<<
for your class:
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;
}
More Related Contents:
- in c++ when i declare an integer variable int a = 200L or int a = 200F or int a = 200U, It allows. How does this happen?
- How to add a number to an integer like a string
- Why ‘&’ reference in not required in classes in C++?
- Why would we call cin.clear() and cin.ignore() after reading input?
- no default constructor exists for class
- Functions with const arguments and Overloading
- Efficient way to determine number of digits in an integer
- Most vexing parse confusion
- How do I check if an object’s type is a particular subclass in C++?
- Error: cannot bind non-const lvalue reference of type ‘int&’ to an rvalue of type ‘int’
- How do you use CreateThread for functions which are class members?
- Multiple inputs on one line
- Why use a const member function?
- Are parent class constructors called before initializing variables?
- Class vs Struct for data only?
- CUDA and Classes
- Difference between long and int data types [duplicate]
- How to access private data members outside the class without making “friend”s? [duplicate]
- sizeof class with int , function, virtual function in C++?
- Issue with cin when spaces are inputted, using string class
- c++ issue with function overloading in an inherited class
- Accessing static class variables in C++?
- Why use !! when converting int to bool?
- Why can’t we declare a namespace within a class?
- c++ integer->std::string conversion. Simple function?
- What do the C and C++ standards say about bit-level integer representation and manipulation?
- C++ Class or Struct compatiblity with C struct
- convert string to integer in c++
- How to convert int to string in C++
- C++ Member Initializer List