Purpose of overloading operators in C++?
<p>What is the main purpose of overloading operators in C++?</p>

<p>In the code below, <code>&lt;&lt;</code> and <code>&gt;&gt;</code> are overloaded; what is the advantage to doing so?</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

class  book {
    string name,gvari;
    double cost;
    int year;
    public:
    book(){};

    book(string a, string b, double c, int d) { a=name;b=gvari;c=cost;d=year; }
    ~book() {}
    double setprice(double a) { return a=cost; }
    friend ostream&amp; operator &lt;&lt;(ostream&amp; , book&amp;);
    void printbook(){
        cout&lt;&lt;"wignis saxeli "&lt;&lt;name&lt;&lt;endl;
        cout&lt;&lt;"wignis avtori "&lt;&lt;gvari&lt;&lt;endl;
        cout&lt;&lt;"girebuleba "&lt;&lt;cost&lt;&lt;endl;
        cout&lt;&lt;"weli "&lt;&lt;year&lt;&lt;endl;
    }
};

ostream&amp; operator &lt;&lt;(ostream&amp; out, book&amp; a){
    out&lt;&lt;"wignis saxeli "&lt;&lt;a.name&lt;&lt;endl;
    out&lt;&lt;"wignis avtori "&lt;&lt;a.gvari&lt;&lt;endl;
    out&lt;&lt;"girebuleba "&lt;&lt;a.cost&lt;&lt;endl;
    out&lt;&lt;"weli "&lt;&lt;a.year&lt;&lt;endl;
    return out;
}

class library_card : public book {
    string nomeri;
    int raod;
    public:
    library_card(){};
    library_card( string a, int b){a=nomeri;b=raod;}
    ~library_card() {};
    void printcard(){
        cout&lt;&lt;"katalogis nomeri "&lt;&lt;nomeri&lt;&lt;endl;
        cout&lt;&lt;"gacemis raodenoba "&lt;&lt;raod&lt;&lt;endl;
    }
    friend ostream&amp; operator &lt;&lt;(ostream&amp; , library_card&amp;);
};

ostream&amp; operator &lt;&lt;(ostream&amp; out, library_card&amp; b) {
    out&lt;&lt;"katalogis nomeri "&lt;&lt;b.nomeri&lt;&lt;endl;
    out&lt;&lt;"gacemis raodenoba "&lt;&lt;b.raod&lt;&lt;endl;
    return out;
}


int main() {
    book A("robizon kruno","giorgi",15,1992);
    library_card B("910CPP",123);
    A.printbook();
    B.printbook();
    A.setprice(15);
    B.printbook();

    system("pause");
    return 0;
}
</code></pre>
