Read two floats with delimiting characters

50 Views Asked by At

I have to read a stdin entry using the istream operator. I have to provide two entries as (x1,y1)(x2,y2) in one line.

cin >> a >> b;

This code internally (called complex.cpp) has this method overridden where we do this

istream& operator>>(istream& in, complex& a) {
    char temp;
    float re, im;
    in >> temp >> re >> temp >> im >> temp;
    a.x = re;
    a.y = im;
    return in;
}

For some reason, It takes the first coordinates and messes up reading the second complex number. To make thing really bad, I put a breakpoint at

in >> temp >> re >> temp >> im >> temp;

and that messes the stream. Help needed to be able read both coordinates.

0

There are 0 best solutions below