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 |
i wanted to know about questions about c,c++ , which is required for placements.... im a fresher
how to swap two numbers in a linked list without exchanging the data but only the links?
what's the difference between function overloading and function overiding?
What are the symptoms of stl?
write a c++ to define a class box with length,breadth and height as data member and input value(),printvalue() and volume() as member functions.
what is an algorithm in terms of STL?
What is stl stand for?
What is Constructor
What is the Difference between CArray and CList?
1 Answers ProdEx Technologies, Siemens,
Write a program to print the swapping in two no and using three variable.
please visit this site you'll find my question this is my homework please answer it if you can http://easyscience.org/ib/lofiversion/index.php/t36168.html
To modify an, existing worksheet. What steps are involved for: 1. Inserting and deleting rows and columns. 2. Printing cell formulas 3Jld displayed values 3. Using the page setup command