Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

cpp insert overload operator

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)
Source by www.tutorialspoint.com #
 
PREVIOUS NEXT
Tagged: #cpp #insert #overload #operator
ADD COMMENT
Topic
Name
1+4 =