I'm writing a class that involves a queue, and I want to overload the instream. I know that for a more simple program, the correct way to overload the instream would be to just assign the input values to the private data members in the class and return. One example would be, with a class such as Distance that has private data members for feet and inches:
For my class, the user will input a string (of numbers) through instream, and I will take that string and break it up into chars. Each char will become the "item" of a node that will then be inserted a queue. So far, what I intend to do is:
1 2 3 4 5 6 7 8 9 10 11 12 13
istream& operator>>(istream &in, LongInt &rhs)
{
rhs.digits.clear(); // clears the original queue
string input; // string to hold input from user
in >> input;
// Here I will iterate over the string with a for each loop
// I will take each char, and insert it into a queue
// The queue program is correct, so assume passing my char
// to the queue program will successfully create a node for the queue
return in;
}
So far, it appears to be working, but I am unsure if this is the correct way to implement overloading >> in this situation. I don't really understand why I am returning "in" as well, as it appears to be useless as I receive the input from the user and successfully create the queue before returning in occurs. Does anyone know if this is the correct way to implement overloading <<?