You should not test for eof() in your while() clause. The reason being that EOF is not flagged until after the read fails. So if temp.read(in) fails (because you reached the end-of-file) you will still push it onto your std::vector<>
One way to fix this would be to change your function read() so that it returns true or false to signal if the read was successful. You can do that like this:
1 2 3 4
bool read(std::fstream &in)
{
return (in >> apples >> oranges);
}
Then you can make that the condition of your while() loop:
1 2 3 4 5
while(temp.read(in))
{
// only do this if read() was successful
data.push_back(temp);
}