change character in file

Discussion in 'C++' started by Boris ©avc, Dec 16, 2003.

  1. Boris ©avc

    Boris ©avc Guest

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

    Thanks for the pointers.
    Regards,
    Boris
    Boris ©avc, Dec 16, 2003
    #1
    1. Advertising

  2. "Boris ©avc" <> 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
    Victor Bazarov, Dec 16, 2003
    #2
    1. Advertising

  3. 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
    Thomas Matthews, Dec 16, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Velvet
    Replies:
    9
    Views:
    14,771
    Joerg Jooss
    Jan 19, 2006
  2. raavi
    Replies:
    2
    Views:
    898
    raavi
    Mar 2, 2006
  3. cgbusch
    Replies:
    6
    Views:
    7,464
    Mike Brown
    Sep 2, 2003
  4. Spacebar265

    Scanning a file character by character

    Spacebar265, Feb 5, 2009, in forum: Python
    Replies:
    18
    Views:
    449
  5. powah
    Replies:
    21
    Views:
    902
    Steven D'Aprano
    Jun 28, 2009
Loading...

Share This Page