By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,947 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

change character in file

P: n/a
How to change character in a file from 'a' to 'b' (g++, linux)?

Thanks for the pointers.
Regards,
Boris
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Boris Šavc" <bo********@odis-info.com> 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
Jul 22 '05 #2

P: n/a
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::put
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

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.