Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Strange Coding Problem - Remove Header from Text File

Strange Coding Problem - Remove Header from Text File
Thread Tools
Fresh-Faced Recruit
Join Date: Mar 2009
Status: Offline
Reply With Quote
Sep 15, 2009, 12:54 AM
 
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 (c++):

Code:
string deleteline = "Name, ID, D.O.B"; //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!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:31 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2