samedi 2 mars 2019

Custom istream end iterator

I want to split a line of text into words and my current code is

vector<string>((istream_iterator<string>(f)),
                                istream_iterator<string>());

where f is an ifstream object. However, this reads to the end of the file, and I want to stop it from reading when it reaches a newline. Is there any way to do something like istream_iterator<string>("\n") so the vector constructor will stop pushing back when it reaches a newline?

Aucun commentaire:

Enregistrer un commentaire