My apologies my c++ abilities are poor (self taught)

I have a text file that needs editing

the first 10 lines of the file needs replacing

but the other 1,000,000 + lines don't

I need the information in the first 10 lines to know what to edit them to

i get the information from the file with ifstream

how do i replace the first 10 lines of this text file without deleting the whole file and just writing those ten lines

is this possible or do i have to loop through the whole file copying to another

Thanks

In my knowledge, you cannot "edit" out lines from a text file. You have to and have to use something(while loop or whatever is suitable, as you said) to copy to a new file and delete the old one.

If the replacement lines aren't exactly the same length as the lines being replaced, you need to rewrite the whole file. If they are the same length you can just overwrite the first ten lines.

thank you both for the fast response

Unfortunately there is no garentee they will be the same length

I guess i will have to go for the long loop

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.