delete a character from a file

G

Guest

Hello everyon

I am using filestream and streamwriter to download and save a xml page from the internet
The problem is that it has 3 bytes at the beginning of the file with garbage that i want to get rid off
so i use a simple code like this

FileStream* fs1 = new FileStream (input, FileMode::Open, FileAccess::ReadWrite)
StreamReader* sr1 = new StreamReader (fs1)
StreamWriter* sw1 = new StreamWriter(fs1)

char c = ' '
for (;;

c = sr1->Read()
if (c == '<'

sw1 ->Flush()
sw1 ->Close()
break

els

sw1 ->Write(' ')



Although the read is done correctly, the write does not appear to function

I don't know whether this code starts the write at the beggining of the file, is there a way to make sure of that
Then is a special function or character for deleting the unwanted characters that i find ?
 
C

Carl Daniel [VC++ MVP]

In order to remove (delete) bytes from a file, you need to re-write the
entire file content, less the part you want to delete, to a new file.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top