2. Stream InsertionStream Insertion
operatoroperator
►Often we need to display the dataOften we need to display the data
on the screenon the screen
►Example:Example:
int i=1, j=2;int i=1, j=2;
cout << “i= ”<< i << “n”;cout << “i= ”<< i << “n”;
Cout << “j= ”<< j << “n”;Cout << “j= ”<< j << “n”;
3. Stream InsertionStream Insertion
operatoroperator
Complex c1;Complex c1;
cout << c1;cout << c1;
cout << c1 << 2;cout << c1 << 2;
// Compiler error: binary '<<' : no// Compiler error: binary '<<' : no
operator // defined which takes a right-operator // defined which takes a right-
hand // operand of typehand // operand of type ‘‘classclass