Search
 
SCRIPT & CODE EXAMPLE
 

CPP

overload stream insert 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 :: initialize 2d vector 
Cpp :: c++ foreach 
Cpp :: bitwise count total set bits 
Cpp :: char ascii c++ 
Cpp :: all possible permutations of characters in c++ 
Cpp :: C++ cin cout 
Cpp :: c++ vector extend vector 
Cpp :: the code execution cannot proceed because glew32.dll was not found 
Cpp :: how to send email in c++ program 
Cpp :: remove decimal c++ 
Cpp :: built in factorial function in c++ 
Cpp :: how to get size of 2d vector in c++ 
Cpp :: how to sort a string alphabetically in c++ 
Cpp :: how to initialize array with new in c++ 
Cpp :: c++ print 3d cube 
Cpp :: initialize vector of vector c++ 
Cpp :: c++ cast to type of variable 
Cpp :: how to check a number in string 
Cpp :: how to empty an array c++ 
Cpp :: to lowercase c++ 
Cpp :: length of string in c++ 
Cpp :: fizzbuzz c++ 
Cpp :: how to use toString method in C++ 
Cpp :: how many months have 31 days 
Cpp :: c plus plus 
Cpp :: set to vector 
Cpp :: cpp define function 
Cpp :: c++ tuple 
Cpp :: double array size c++ 
Cpp :: c++ vector first element 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =