mercredi 7 février 2018

C++ Specify input from istream and test it

I have a class basically representing a tuple (double x, doubly y) and I have overloaded the << operator so I can print the class. Now I want to do the same for >>, and that it only supports following formats: x, (x) and (x,y).

I following code:

std::ostream & operator<< (std::ostream &output, tuple &c){
    output << "(" << c.x << "," << c.y << ")" << endl;
    return output;
}

std::istream & operator>> (std::istream & input, tuple &c){
    // Check for following patterns: x, (x) or (x,y)
}

Can I loop through input and regex match? In that case how? Also how could I test that it's actually working, something like this std::cin >> "(10.2,5.5)" or do I need to read from a file to test?

Aucun commentaire:

Enregistrer un commentaire