regan_a
asked on
Delete last character in a file
Hello, I am writing a simple text editor and would like to figure out how to delete the last character in a file that I am writing to. Right now when I hit backspace, in the dos window it moves back a character but in the text file I just get a big . Here is my source so far so you can understand how this file is being written to:
void input_text()
{
// Initialize variables and open file for writing
char ch;
ofstream textfile("textfile.txt");
// Read in characters and store to file
while (ch != ESC)
{
ch = getch();
if (ch != ESC)
{
if (ch == ENTER)
ch = '\n';
textfile << ch;
cout << ch << flush;
}
}
// Close file
textfile.close();
}
I can read in backspace just like I can enter and esc but I don't know how to move one space back in the file. Any help would be appreciated!
void input_text()
{
// Initialize variables and open file for writing
char ch;
ofstream textfile("textfile.txt");
// Read in characters and store to file
while (ch != ESC)
{
ch = getch();
if (ch != ESC)
{
if (ch == ENTER)
ch = '\n';
textfile << ch;
cout << ch << flush;
}
}
// Close file
textfile.close();
}
I can read in backspace just like I can enter and esc but I don't know how to move one space back in the file. Any help would be appreciated!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh, I know it is strange, I just wanted to see if it could be done :) Regularly I would load it into the buffer but I am learning the language and trying to imagine as many abstract ways of learning different things as possible. Anyways, thanks for the help/advice you two.
small note--
almost anything can be done in programming world.. and somethings are preferred over most others
almost anything can be done in programming world.. and somethings are preferred over most others
then its better that u should use the buffer method.. load the file in -inmemory buffer do the changes and then save the buffer back to the file
editing straight to the file is nuthing but strange..