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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / abed

in c++ << and >> overloaded as the insertion and out put
symbole

Is This Answer Correct ?    2 Yes 1 No

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

Answer / ramya

"<<" this inserssion perrator is used for output the
messages&values
">>"this exsersition operator is used for input the values
sentax:

return_type operator op(arguments_list)
{
----
----
}

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More STL Interview Questions

write a program that input four digit number and find how many 7 that number contains

4 Answers  


When did c++ add stl?

0 Answers  


Explain when u will use Observer pattern and how u will implement in c++ .

1 Answers  


how to get the sum of two integers?

2 Answers  


What are the symptoms of stl?

0 Answers  






i wanted to know about questions about c,c++ , which is required for placements.... im a fresher

0 Answers   NDS,


what is use of for loop?

9 Answers   Wipro,


What is a standard template library (stl)?

0 Answers  


give me the defination of inheritance?

5 Answers   Infosys,


What is a stl vector?

0 Answers  


sir please send me bpcl previous question papers

0 Answers   BPCL Bharat Petroleum,


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

0 Answers  


Categories