dimanche 10 avril 2022

Reading Strings and integers overloading insertion operatror

I am trying to read a text file with records like these:

Someone Name 10
SomeoneElse Name 30

I would like to read each record and save the contents in class object Player that has to members : a string with the name and an int with a score. cin can't read strings, so how can I overload it to the desired action (ignoring the blank)?

std::istream& operator>> (std::istream& stream, Player player)
{
    stream >> player.getPlayerName();
    stream >> player.getPlayerScore();
    return stream;  
}

Aucun commentaire:

Enregistrer un commentaire