Question: C++ Ignoring New Lines while Reading Files I have trouble with the 2 following files and IMPORTANT NOTE: The Ns are New Lines, they are
C++ Ignoring New Lines while Reading Files
I have trouble with the 2 following files

and

IMPORTANT NOTE: The "N"s are New Lines, they are NOT in the file and only serve as a visual.
Problem: My function to read a file does not appear to work when there are multiple newlines or if newlines separate a record I should add to a linked list. Each file ends in at least one new line, but as shown in the first file, it will not work if there's another new line after it.
My Read File Function:

{id: 1234567, first: Mary, last: Green, DOB: 1996-10-03,GPA: 4.0) {id: 1234568, first:Peter, last:White, DOB: 1997-05-22,GPA: 3.8} {id: 1654238, first:Nick, last:Park,DOB: 1995-08-18, GPA:4.0) {id: 1234587, first:Katy, last: Green, DOB: 1995-08-18, GPA: 4.0} {id: 1234567, first: Mary, last: Green, DOB: 1996-10-03, GPA: 4.0} {id: 1234568, first:Peter, last: White, DOB: 1997-05-22, GPA: 3.8} {id: 1654238, first: Nick, last:Park, DOB: 1995-08-18, GPA:4.0} {id: 1234587, first:Katy, last: Green, DOB: 1995-08-18, GPA: 4.0) {id: 1654238, first: Nick, last:Park, DOB: 1995-08-18, GPA:4.0} {id: 1654238, first:Nick, last:Park,DOB: 1995-08-18, GPA:4.0} bool LinkedList::readFile(string filename) { ifstream ifs(filename); string str; while (getline(ifs, str)) { str.erase (remove(str.begin(), str.end(), ' '), str.end(); str.erase(remove(str.begin(), str.end(), ' '), str.end(); if (str.find("delete") != string: :npos) { int loc = str.find("delete") + 6; int loc2 = str.find(" "); loc++; int key = stoi(str.substr(loc, loc2 - loc)); deleteItem(key); else if (str.find("del") != string::npos) { int loc = str.find("del") + 3; int loc2 = str.find(' '); loc++; int key = stoi(str.substr(loc, loc2 - loc)); deleteItem(key); else { additem(str); return true
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
