how to delete a word from a file?

Jul 11, 2009 at 7:33am
how to delete a word from a file?

the delete address is filepointer = 32

can u give an example?

thanks
Jul 11, 2009 at 8:31am
and how are those words stored in file? one word per line?
Last edited on Jul 11, 2009 at 8:31am
Jul 11, 2009 at 8:41am
stored in file use WriteFile() for win32 api
Jul 11, 2009 at 3:10pm
Typically the answer is:

read source file line by line/word by word/etc
make changes
save to temp file
close files

delete source file
rename temp file to source file


another possibility is:
load source file into memory (say, a std::deque)
make changes
save memory to source file

Good luck!
Jul 12, 2009 at 5:27am
hi, Duoas , i choose to use the method of load source file into memory (::deque)

the line is "goes Goes I am Phappy"--> i want to change to "goes Goes I am happy"

change the line "goes Goes I am Phappy"--> " "
by

ReadFile(happy.txt,...) // put the line into a wstring
setFilePointer( );

writefile();

the problems come, i just know how to insert string into a file, by how to override or delete, it really a problem~ ~


Last edited on Jul 12, 2009 at 5:40am
Jul 12, 2009 at 5:50am
ReplaceFile()
Replaces one file with another file, with the option of creating a backup copy of the original file. The replacement file assumes the name of the replaced file and its identity.

http://msdn.microsoft.com/en-us/library/aa365512(VS.85).aspx



DeleteFile Function()
Deletes an existing file.
http://msdn.microsoft.com/en-us/library/aa363915(VS.85).aspx


MoveFile Function
Moves an existing file or a directory, including its children.
http://msdn.microsoft.com/en-us/library/aa365239(VS.85).aspx
Last edited on Jul 12, 2009 at 6:24am
Jul 12, 2009 at 6:23am
To write string line by line use escape

http://www.cplusplus.com/forum/windows/11863/
Topic archived. No new replies allowed.