Skip to content

Instantly share code, notes, and snippets.

@yudhastyawan
Created January 27, 2020 05:44
Show Gist options
  • Save yudhastyawan/fb8c68349153d2f46f68e79e4ae5069d to your computer and use it in GitHub Desktop.
Save yudhastyawan/fb8c68349153d2f46f68e79e4ae5069d to your computer and use it in GitHub Desktop.
An example of costumizing std::cout in C++
#include <iostream>
#include <ostream>
struct Vector
{
int x, y;
Vector(int X, int Y) : x(X), y(Y) {}
};
std::ostream& operator<<(std::ostream& stream, const Vector& other)
{
stream << other.x << " , " << other.y;
}
int main()
{
Vector vector(2,3);
std::cout << vector << std::endl; // print -> 2 , 3
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment