Problem with overloaded operator(>>)

I am very very new to c++. I learn java for the past 2 years the my college decided to change back to c++ so this is my first year in c++. Anyway i have an lab ahead of me this week which is asking me to overload '>>' operator to accept and format fractions. i have written the code below but my problem is when i enter multiple fractions on one line it will just take the first one and stop. Please Help.
Thanks

my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
istream& operator>>
(
istream& inStream,
Fraction& f
)
{
    char buffer[100];
    inStream.getline(buffer,100,'/');
    f.numerator = atoi(buffer);
    inStream.get(buffer,100);
    f.denominator = atoi(buffer);
    return inStream;
} 
It is because you are reading the entire line on line 8...

Read an integer, skip whitespace, read the '/', read an integer.

1
2
3
4
5
    inStream >> f.numerator;
    inStream >> ws;
    if (inStream.get() != '/') inStream.setstate( ios::failbit );
    inStream >> f.denominator;
    return inStream;

If you really want to get fancy, you can do extra checking to make sure you don't read past EOL when skipping whitespace.

Also, avoid using atoi() -- you've got C++ streams to do that stuff for you.

Hope this helps.
It worked like a charm.
Thank you very much.
Topic archived. No new replies allowed.