I have a file I can add and remove information from, but during the remove function (which is an array of 50) each line that doesn't have any information on it (up to the 50 mark) gets set to an empty line. Basically, if there were 3 items in the file, there would be 47 lines of nothing added where nothing was previously. So I am looking for the absolute simplest way possible to go through the file and delete any empty lines.
Simplest way possible would be nice, as I am still learning C++ and don't understand a lot of the advanced features yet.
bool removeFriend(string currentFriend)
{
bool successFail = false;
string friendArray[50];
int counter = 0;
string debtReason, name, amountOwed;
ofstream fout;
ifstream fin;
fin.open("moneyFriendsOweMe.txt");
if (fin.is_open())
{
while (isalpha(fin.peek()))
{
getline(fin, name);
if (name != currentFriend)
{
friendArray[counter] = name;
counter ++;
getline(fin, debtReason);
friendArray[counter] = debtReason;
counter ++;
getline(fin, amountOwed);
friendArray[counter] = amountOwed;
counter ++;
}
else
{
getline(fin, debtReason);
getline(fin, amountOwed);
successFail = true;
}
}
fin.close();
}
fout.open("moneyFriendsOweMe.txt");
if (fout.is_open())
{
for(int i = 0; i < 50; i++)
{
fout << friendArray[i];
fout << "\n";
}
fout.close();
}
return successFail;
}