Search
 
SCRIPT & CODE EXAMPLE
 

CPP

overload stream extract cpp

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)
Comment

PREVIOUS NEXT
Code Example
Cpp :: udo apt install dotnet-sdk-5 
Cpp :: why are inline keyword in header c++ 
Cpp :: How to find the suarray with maximum sum using divide and conquer 
Cpp :: what does the modularity mean in c++ 
Cpp :: c++ Program for Sum of the digits of a given number 
Cpp :: c++ program to reverse an array 
Cpp :: change int to string c++ 
Cpp :: int to hex arduino 
Cpp :: ViewController import 
Cpp :: c++ binary search 
Cpp :: struct and pointer c++ 
Cpp :: c++ structure 
Cpp :: debugging c/c++ with visual studio code 
Cpp :: cpp vector2 
Cpp :: cpp loop through object 
Cpp :: C++ Volume of a Cylinder 
Cpp :: sort a vector c++ 
Cpp :: how to sort vector of struct in c++ 
Cpp :: c++ average 
Cpp :: how to specify the number of decimal places in c++ 
Cpp :: image shapes in opencv c++ 
Cpp :: sort vector of strings 
Cpp :: how to calculate bitwise xor c++ 
Cpp :: Converting to string c++ 
Cpp :: Max element in an array with the index in c++ 
Cpp :: find in unordered_map c++ 
Cpp :: cpp ifdef 
Cpp :: c++ get pointer from unique_ptr 
Cpp :: long pi in c++ 
Cpp :: c++ read matttrix from text file 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =