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
find wether specific word is inside a pool of word and what is the direction e.g. north

em Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using ''Content here, content here'', making it look like readable English. Many desktop publis

#question.Write a c++ program to accept and print a 1_d array

Explain string constants in c language - Escape Sequences? Illustrations are "945", "hello", "well done", "5+3". The character constant (example 'x') isn't equivalent to the st

Binary search in array: - C program: Write a program in c to define binary search in array. void main()                 {                 clrscr();

6999066263304447777077766622337778 -----> message sent by the first smuggler. my name is robert---------> message decoded by the second smuggler. Where ‘0’ denotes the "space".

write a pseudocode algorithm for a program that accepts a number and prints out its reciprocal(1/n) is required.the program should prevent the user from entering zero by asking t

Respected Sir, I want the above written text in a C program

- Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles. The user should be able to view all DVD titles in his library, add and d

At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with thes