I have a file named 1.txt, it contains 3 lines, each line is stored in an object of class entry
as follows:
1* 10/12/2020 5:30 a 11:15 p 0 0 0 0 -----
2* 11/12/2020 3:45 a 5:46 a 0 0 0 0 -----
3* 12/12/2020 5:46 a 4:56 p 34.6 0 0 0 blah
and I'm reading from this file line by line into Entry e
, and storing each entry into std::vector<Enrty>records
like this:
void read_records(std::ifstream file, Entry e, std::vector<Entry>&records)
{
std::string line;
std::cout << "READING TEXT FILE CONTENTS..." << std::endl;
while (file)
{
getline(file, line);
e.read_text(tokenize(line)); // tokenize tokenizes line to tokens and e.read_text stores data from that line into e
records.push_back(e);
e.reset(); // this resets e back to original state
}
}
when I display records
after calling this function it gives me an extra Entry in records like so,
The contents in std::<Entry>records
are :
1* 10/12/2020 5:30 a 11:15 p 0 0 0 0 -----
2* 11/12/2020 3:45 a 5:46 a 0 0 0 0 -----
3* 12/12/2020 5:46 a 4:56 p 34.6 0 0 0 blah
3* 12/12/2020 5:46 a 4:56 p 34.6 0 0 0 blah // I'm getting this extra entry in records when the file only contains 3 entries.
Please explain why this is happening and now to fix this in visual studio C++.