struct coord {
int x, y;
/// take 2 inputs and put into coord, using overloaded >> operator
friend istream& operator>>(istream& input, coord &c) {
input >> c.x >> c.y;
return input;
}
/// extract coord in point notation
friend ostream& operator<<(ostream& output, const coord &c) {
output << "(" << c.x << "," << c.y << ")"; // (x,y)
return output;
}
};
//usage:
coord pnt;
cin >> pnt; //cin contains: 1 2
cout << pnt; // (1,2)
Code Example |
---|
Cpp :: c++ |
Cpp :: What is the story of c++ |
Cpp :: c++ get char of string |
Cpp :: splice string in c++ |
Cpp :: remove element from array c++ |
Cpp :: matrix transpose in c++ |
Cpp :: round double to 2 decimal places c++ |
Cpp :: destructor in c++ |
Cpp :: C++ break and continue |
Cpp :: input in c++ |
Cpp :: check if a string is palindrome cpp |
Cpp :: hello world program in c++ |
Cpp :: how to debug c++ code in vs studio code |
Cpp :: Pyramid pattren program in C++ |
Cpp :: fast way to check if a number is prime C++ |
Cpp :: how to sort in descending order in c++ |
Cpp :: cpp string slice |
Cpp :: cout c++ |
Cpp :: c++ pass array to a function |
Cpp :: factorial loop c++ |
Cpp :: getline(cin string) not working |
Cpp :: integer range in c++ |
Cpp :: convert characters to lowercase c++ |
Cpp :: c++ char array size |
Cpp :: position of max element in vector c++ |
Cpp :: define in cpp |
Cpp :: c++ #include |
Cpp :: char to string c++ |
Cpp :: how to replace part of string with new string c++ |
Cpp :: string comparison c++ |