Bit shift operators for IO

suggest change

The operators << and >> are commonly used as “write” and “read” operators:

For a user-defined type the overload is a non-member, because the left operand is the stream, not your type. The two operands have different types:

Example:

// Overload operator<< so a Vector can be written to an std::ostream.
std::ostream& operator<<(std::ostream& lhs, const Vector& rhs)
{
    lhs << "x: " << rhs.x << " y: " << rhs.y << " z: " << rhs.z << '\n';
    return lhs;
}

Vector v = { 1, 2, 3};

//Now you can do
std::cout << v;

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents