Describe, how can i provide input for my class fred?, C/C++ Programming

A: Use operator overloading to present a friend right-shift operator, operator>>. It is similar to the output operator, except the parameter doesn't contain a const: "Fred&" instead of "const Fred&".

#include class Fred {

public:

friend std::istream& operator>> (std::istream& i, Fred& fred);

... private:

int i_; // Just for illustration

};

std::istream& operator>> (std::istream& i, Fred& fred)

{

return i >> fred.i_;

}

int main()

{

Fred f;

std::cout << "Enter a Fred object: ";

std::cin >> f;

...

}

Note  down that operator>> returns the stream. It is so the input operations may be cascaded and/or utilized in a while loop or if statement.

 

Posted Date: 3/20/2013 8:15:30 AM | Location : United States







Related Discussions:- Describe, how can i provide input for my class fred?, Assignment Help, Ask Question on Describe, how can i provide input for my class fred?, Get Answer, Expert's Help, Describe, how can i provide input for my class fred? Discussions

Write discussion on Describe, how can i provide input for my class fred?
Your posts are moderated
Related Questions
Why are all header files not declared in every C program? - Declaring all header files in each program would result in increase in overall file size and load of the program. It

decoding message

Write a program called Converter that does three types of metric conversions. Your program should prompt the user for the selection conversion, prompt for input data, and display t

dispaly the last ant on rod

Question : (a) What is a structure? Provide a simple example of your own to illustrate this feature. (b) How does a structure differ from an array? (c) Describe a structu

Implement the search property from catalogue menu option.  After selecting this option the user should be asked to specify the property using the following sub-menu: 1. Specif


Define the Increment and Decrement Operators in c language? C offers two special operators -and ++ called decrement and increment operators respectively and these are unary ope

Project Description: I would like to be building regarding a complex mobile application build as we require the signing of an NDA. My firm in based in Montreal Canada and we are

how do i print out invalid input?