how to overload << and >> operator in c++
Answers were Sorted based on User's Feedback
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 |
Answer / abed
in c++ << and >> overloaded as the insertion and out put
symbole
Is This Answer Correct ? | 2 Yes | 1 No |
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 |
In what cases using of a 'template' is a better approach then using of a 'base class'?
6 Answers Lucent, Mind Tree, Wipro,
What does stl stand for in basketball?
i want a road rash 3d game code if some one know please help me
What is the use of stl?
give me the defination of inheritance?
what is the difference between thread and process
Write a program to print the swapping in two no and using three variable.
c# support late binding or early binding.
Explain when u will use Observer pattern and how u will implement in c++ .
write a program that input four digit number and find how many 7 that number contains
Explain stl.
Is string part of stl?