Remove last character in file.

How do i remove the last letter in a txt file.

Page 1 of 1

4 Replies - 6989 Views - Last Post: 09 April 2009 - 10:56 AM Rate Topic: -----

#1 Ion  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 20-December 08

Remove last character in file.

Post icon  Posted 09 April 2009 - 08:37 AM

Hello,I have been tinkering with fstream lately and i wonder how i remove the last letter in a file.

I have been wondering about
ignore()
but that doesnt work.Google hasnt been of help,just plainly tell me what function that can do this for me.
Is This A Good Question/Topic? 0
  • +

Replies To: Remove last character in file.

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Remove last character in file.

Posted 09 April 2009 - 09:07 AM

I'm not clear on what you want to do.
Do you want to re-write the file minus the last character?
Was This Post Helpful? 0
  • +
  • -

#3 Ion  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 20-December 08

Re: Remove last character in file.

Posted 09 April 2009 - 10:04 AM

I want to remove the last character in a text file,i havent intended to rewrite anything.
Just make the last character null.
Was This Post Helpful? 0
  • +
  • -

#4 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Remove last character in file.

Posted 09 April 2009 - 10:50 AM

I suppose you can use seekp() to set the position of the put pointer to the last character (or any character for that matter) and then put('\0') there.
Was This Post Helpful? 0
  • +
  • -

#5 Ion  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 20-December 08

Re: Remove last character in file.

Posted 09 April 2009 - 10:56 AM

Fixed,Thanks

This post has been edited by Ion: 09 April 2009 - 02:16 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1