Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > change character in file

Reply
Thread Tools

change character in file

 
 
Boris Šavc
Guest
Posts: n/a
 
      12-16-2003
How to change character in a file from 'a' to 'b' (g++, linux)?

Thanks for the pointers.
Regards,
Boris


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      12-16-2003
"Boris Šavc" <(E-Mail Removed)> wrote...
> How to change character in a file from 'a' to 'b' (g++, linux)?


Open file for reading and writing ("direct access").
Read until found the character to change.
Position to that character.
Write the new character.
Repeat until no more characters to change are found.

Victor


 
Reply With Quote
 
 
 
 
Thomas Matthews
Guest
Posts: n/a
 
      12-16-2003
Boris Šavc wrote:
> How to change character in a file from 'a' to 'b' (g++, linux)?
>
> Thanks for the pointers.
> Regards,
> Boris
>
>


You have two choices: overwrite and new file. Since you
are changing one character to another (same size data)
you _can_ overwrite the old one. The alternative method
is to read all data that you are not interested in and
write it to a new file. Write the new value to the new
file and so on.

Look up:
fstream
seekp
seekg
tellp
tellg
istream::get
ostream:ut
read
write


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
change the first character of the line to uppercase in a text file powah Python 21 06-28-2009 05:36 AM
Scanning a file character by character Spacebar265 Python 18 02-22-2009 03:21 PM
A Paradise DNS address change? What change? There was no change. Tony Neville NZ Computing 7 09-22-2006 01:02 PM
character encoding +missing character sequence raavi Java 2 03-02-2006 05:01 AM
getting the character code of a character in a string Velvet ASP .Net 9 01-19-2006 09:27 PM



Advertisments