Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Overloading IO Stream

//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;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to calculate the sum of primary diagonal matrix and secondary diagonal matrix using c++ 
Cpp :: Chef and Feedback codechef solution in cpp 
Cpp :: http://dcnet.ddns.ma/Connecter_Tuteur 
Cpp :: c++ map value int to string 
Cpp :: how to analyse a poem 
Cpp :: how to write string in c++ 
Cpp :: if c++ 
Cpp :: assignment operator 
Cpp :: c++ & operator 
Cpp :: how to code a segment tree in c++ 
Cpp :: how to parse using stringstream 
Cpp :: batch to exe 
Cpp :: c++ destructor 
Cpp :: passare un array a una funzione 
Cpp :: string array 2d c++ 
Cpp :: create a bitset of 1024 bits, 
C :: bold text in c 
C :: c check if file exists 
C :: pygame draw transparent rectangle 
C :: grepper vscode 
C :: dvlprroshan 
C :: malloc int array c 
C :: find the largest number among five numbers in c language 
C :: A binary tree whose every node has either zero or two children is called 
C :: hi servicenow 
C :: malloc in c 
C :: how to modulo in c without % 
C :: gcc option to show rules of makefile 
C :: read from stdin c 
C :: measure time in c 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =