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
Prepare an iPad application Clash of Clans like game I would like to prepare a free city building app with the in app purchase possibility. An example game could be Clash of Cla

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

find area under the curve y=f(x) between x=a &y=b integrate y=f(x)

Writing and compiling a program from a given Use Case definition. Follow the Average Temperature in Paradise

Define Commonly Used Built-in Library Functions? Comprise opened a file pointer you will desire to use it for either input or output. The C language supplies a set of functions

Need Payment Gateway Integration Expert Project Description: I am seeking for expert payment gateway integration. You must have done or have experience with integrating me

Access privileges 1. If the designer of the base class needs no one, not even a derived class to access a member, then that member should be made private. 2. If the designer

Is always the default constructor for Fred Fred::Fred()?

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Program to store family members details in C++: #include #include #include struct record {   char name[30];   int age;   char state[40]; }x; //cal