Connecting Tech Pros Worldwide Forums | Help | Site Map

Delete a character at some point in file

Member
 
Join Date: Mar 2007
Location: Montevideo, Uruguay (really far)
Posts: 84
#1: Oct 5 '07
Hi guys. I want to know how i can delete a character stored in text document i open with C++. I need to delete a single character. I thought of "writing" the character that equals to the backspace but it doesn't seem to work, any ideas??

Imagine this is the file:

Hello World

I want to delete a character depending on the pointer's position, for example deleting the "W", do you have any ideas??

Thanks a lot people!

Ganon11's Avatar
Moderator
 
Join Date: Oct 2006
Location: New York, United States of America
Posts: 3,428
#2: Oct 5 '07

re: Delete a character at some point in file


I'm not sure you can - you would have to open the file with an ifstream variable, read in the whole file, close the ifstream variable, change the character (or get rid of it), open the file with an ofstream variable, write the altered message, and close the file.
Member
 
Join Date: Mar 2007
Location: Montevideo, Uruguay (really far)
Posts: 84
#3: Oct 8 '07

re: Delete a character at some point in file


Quote:

Originally Posted by Ganon11

I'm not sure you can - you would have to open the file with an ifstream variable, read in the whole file, close the ifstream variable, change the character (or get rid of it), open the file with an ofstream variable, write the altered message, and close the file.

How stupid I am! I hadn't thought of that! It's for high school so i'm not looking for performance, so i am gonna do that! Thanks! Have to admit i always get answers to my questions... That's something great about this site... There should be somewhere where all the c++ functions are listed and ordered depending on what they are used for... Do you know any sites?
Ganon11's Avatar
Moderator
 
Join Date: Oct 2006
Location: New York, United States of America
Posts: 3,428
#4: Oct 8 '07

re: Delete a character at some point in file


www.cplusplus.com is a great site I use all the time.
Reply