   C++ Custom Inserters and Extractors
  I tested one of the programs in my C++ book ('C++ A Beginner's Guide' by Herbert Schildt) and it did not work.The code is exactly the same as in the book. Can you spot an error?// Demonstrate custom inserters and extractors.#include <iostream>using namespace std;class ThreeD {int x, y, z; // 3-D coordinatespublic:ThreeD(int a, int b, int c) { x = a; y = b; z = c; }friend ostream &operator<<(ostream &stream, ThreeD obj); // this now has access to private data in ThreeDfriend istream &operator>>(istream &stream, ThreeD obj);};// Display X, Y, Z coordinates - ThreeD inserter.ostream &operator<<(ostream &stream, ThreeD obj){stream << obj.x << ", ";stream << obj.y << ", ";stream << obj.z << "\n";return stream; // return the stream}// Get three-dimensional values - ThreeD extractor.istream &operator>>(istream &stream, ThreeD obj){cout << "Enter X, Y, Z values: ";stream >> obj.x >> obj.y >> obj.z;return stream;}int main() {ThreeD a(1, 2, 3);cout << a; // use ThreeD inserter to output coordinatescin >> a;cout << a;return 0;}When I enter say: 5 8 3it still returns '1, 2, 3' as the coordinates. The extractor does not seem to work.Any help is appreciated. Thank you!   
  The problem is in your operator implementations. You have the obj parameter being passed by value, which means that a new copy of the object is passed into the function. The original will remain unchanged; all you do is modify a temporary value which is then immediately discarded.To fix this, simply change the ThreeD obj parameter to ThreeD& obj for the >> operator, and const ThreeD& obj for the << operator.Also, thread moved to For Beginners.   ;  Thank you very much for your quick and helpful reply.It is all solved now.Thanks!   ;cout << "Enter X, Y, Z values: ";It doesn't seem to make that much sense to prompt for things in >> operator. The stream is an istream, which means it could be std::cin, but it also could be used for reading from file or doing a conversion from string with stringstream. It doesn't make sense to prompt a file to Enter values.I also have a feeling that >> should be able to read in anything that is written out with <<. If you use << to write a ThreeD to a file, >> should be able to read the same ThreeD from the file. In your case it wouldn't be so, since >> will not be able to handle the commas. (Which makes << and >> somewhat hard to implement in some cases. Perhaps you should have a separate method for reading from std::cin?)   ;  By all accounts, books by Herbert Schildt are known for this sort of thing.   