Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

how to overload << and >> operator in c++

Answer Posted / manav sharma

class chocoBox {
private:
int pieCount;
float boxPrice;

public:
// By giving default arguments, const acts like
// 0, 1 and 2 argument contructor
myClass(int pCount = 10, float bPrice = 20.0)
: pieCount(pCount), boxPrice(bPrice)
{ }

int getPieCount() { return pieCount; }
float getBoxPrice() { return boxPrice; }
void setPieCount(int pc) { pieCount = pc; }
void setBoxPrice(float bp) {boxPrice = bp; }
};

/* Lets overload the operator << of ostream class. We will
return a reference of ostream class for cascading calls
e.g. cout<<obj1<<obj2
*/
ostream& operator<< (ostream &stream, const myClass &obj)
{
stream<<obj.GetPieCount<<" "<<obj.GetBoxPrice<<endl;
return (stream);
}

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the various types of stl containers?

1152


Who created stl?

1150


What do stl stand for?

1117


In what scenario does the Logical file and Physical file being used?

2838


write a program to convert a decimal number in to its equivalent binary number?

2653


Can we use stl in coding interviews?

1802


How stl is different from the c++ standard library?

1207


What is stl stand for?

1220


Explain stl.

1345


What is meant by stl in c++?

1132


draw a flowchart that accepts two numbers and checks if the first is divisible by the second.

3367


What is the use of stl?

1080


What does stl stand for in basketball?

1134


What is a standard template library (stl)?

1110


What is a stl vector?

1232