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
Question 1 Implement a class stack which simulates the operations of the stack allowing LIFO operations. Also implement push and pop operations for the stack 2 Explain the c

Use 16 digit credit card numbers that contain 15 digits an 1 check digit. The format of the card number consists of the 15 digits followed by the check digit. The check digit is co

write a atm program in c with inbuilt functions for 1782?

F r i e n dly Function: A class can have public members and private members.   The public member can be used through the class using dot operator.   Where as private me

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

Study the given class specification and answer the questions that follow: class Person { private:   string name;   int yrBorn;   int yrDied;   public:   Per

Write an algorithm to print all even numbers in descending order and draw the flowchart.

What are  P r im a r y D a t a T y p es? Integer can be defined according to the size of the data and it can be modified further by using keyword unsigned and si

There are ''n'' ants on a ''n+1'' length rod. The ants are numbered from 1 to n and are initially placed at positions starting from position 1 till position n. They are moving eith

Problem Implement a class called employee that contains name, employee number and department code. Include a member function getdata() to get data from user and store it in the