Przeciążenie strumienia IO
//Overloading C++ Stream , Extraction Operator| C++ Programming
#include <bits/stdc++.h>
using namespace std;
class Person
{
string name;
int age;
public:
Person()
{
this->name = "No nmae";
this->age = 0;
}
friend ostream &operator<<(ostream &output, Person &p);
friend istream &operator>>(istream &input, Person &p);
};
ostream &operator<<(ostream &output, Person &p)
{
output << "What the devil " << endl;
output << "My name is " << p.name << " and My age is " << p.age << endl;
return output;
}
istream &operator>>(istream &input, Person &p)
{
input >> p.name >> p.age;
return input;
}
int main()
{
cout << "Enter the name and age " << endl;
Person ak;
cin >> ak;
cout << ak;
return 0;
}
Akash