As soon as you said this:
Could anyone tell me why this code read an extra line?
I immediately looked for this:
while (! in_stream.eof());
This is a very common problem when testing eof() for an end of file condition. Instead try this:
//Test the return condition of the file extraction, much better than eof()
while(in_stream.get(next_symbol))
{
//do stuff
}
//Read the file safely without ever going out of bounds
while(getline(in_stream, data))
{
//do amazing things
}
This might require some minor restructuring of your code, but this is the safe and preferred method for reading a file without having to test eof().