So totally while loop run 4 times. But it should be only three time.
if (file.is_open()){
while (file.good() && !file.eof())
{
getline ( file, label, ',' );//label is a string
getline ( file, name, '\n' );//name is a string
You can also re-write the loop to avoid having to do that logic. There are examples in the forums on this, or the web, and I can't type much right now.
It's always wrong to check the stream status in the loop condition. It is possible to work around that wrong piece of code to make it work, but it's best to do it right to start with.
To do it right, realize what you're testing: file.good() and file.eof() and all other stream status tests answer the question: "did the last read complete successfully?". To use that test correctly you need to read, then test. As in jonnin's example above, or, if you don't need to take different branches between eof and errors, just look at the result of the input operation directly:
As cubbi explained, you read 3 records. No problem. The file is conceptually at eof, but the eof condition has not been set yet. The eof flag will only be set when you attempt a read and there is no record to be read.
At the top of the loop for the 4th iteration, eof is still false. You proceed to attempt two getline operations. Neither one succeeds because the eof flag has now been set. You then proceed with a couple of erases as if the getlines had succeeded.