Hello everybody, I want to create a program that removes the first line from a text (csv) file (which is a header).
I used this code:
string deleteline = "Name, ID, D.O.B, etc., etc."; //contains the Header information to be removed
string line;
ifstream sup;
sup.open("DOWNLOADED_DATA.csv");
ofstream temp;
temp.open("temp.csv");
while (getline(sup,line))
{
if (line != deleteline)
{
temp << line << endl;
}
}
temp.close();
sup.close();
The code works as desired, creating a second file which indeed has the header removed. What is werid is that it copies about 95% of the file over, but not the entire file.
For example, if the non-header-removed file ends like with the last three lines like this:
1986-09-10,35.63,35.88,34.75,35.00,2737600,3.99
1986-09-09,34.63,36.00,34.63,35.75,5398400,4.08
1986-09-08,35.00,35.00,33.63,34.75,4522400,3.97
the modified (header-removed file), only makes it to:
1986-10-08,32.88,33.00,32.25,32.75,4021600,3.74
1986-10-07,34.00,34.13,32.88,33.00,4577600,3.77
1986-10-06,33.75,34.2
It doesn't even finish the last line that it was working on!
Any help would be greatly appreciated. Thank you very much!