lundi 4 septembre 2017

How to read end of the line from text file c++11

I have text file:

7,12,16,20,18,13,6 
9/11/2014

I need to read only the first line into vector and then read date from second line. I've tried this:

while (u >> number ){
        u >> c;
        v.push_back(number);
    }

With u >> number I read numbers from file and with u >> c I read commas. After the loop ends c has value of '9' from second line so I can't read date with:

`u >> d >> line >> m >> line >> g;`

But I don't know hot to break the loop when it comes to the of the first line. I tried if(u.peek()=='\n') break; but id does not work, my program crashes. Can you please help me solve this problem? Thank you!

Aucun commentaire:

Enregistrer un commentaire