Bit shift operators for IO

suggest change

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

The way they do this is similar if you wanted to overload them “normally” outside of the class/struct, except that specifying the arguments are not of the same type:


//Overload std::ostream operator<< to allow output from Vector's
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:

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

Table Of Contents