Created
January 27, 2020 05:44
-
-
Save yudhastyawan/fb8c68349153d2f46f68e79e4ae5069d to your computer and use it in GitHub Desktop.
An example of costumizing std::cout in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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