getline and deleteline

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ron Eggler

    #1

    getline and deleteline

    Hi,
    I am reading out a text fileusing following lines:
    [C++]
    ifstream ifs (RECORD_FILE, ifstream::in );
    while( getline(ifs,rec ordStr) ) { // while until file is empty
    cout << "Read from file: " << recordStr << endl;
    recordStrQueue. push(recordStr) ; // push the read line into the queue
    }
    ifs.close();
    [/C++]
    Now i would like to delete the line in the file as soon as it's read into
    the queue.
    How can i delete a line? i probably need to add "ifstream:: out" when
    defining my handle. But I didn't find a method to delete a line.

    Thanks for your help!
    --
    chEErs roN
  • Victor Bazarov

    #2
    Re: getline and deleteline

    Ron Eggler wrote:
    I am reading out a text fileusing following lines:
    [C++]
    ifstream ifs (RECORD_FILE, ifstream::in );
    while( getline(ifs,rec ordStr) ) {
    // while until file is empty
    cout << "Read from file: " << recordStr << endl;
    recordStrQueue. push(recordStr) ;
    // push the read line into the queue }
    ifs.close();
    [/C++]
    Now i would like to delete the line in the file as soon as it's read
    into
    the queue.
    How can i delete a line? i probably need to add "ifstream:: out" when
    defining my handle. But I didn't find a method to delete a line.
    Generally, it is often _impossible_ to *delete* anything from a file
    directly. Filesystems just don't support that action. It is usually
    accomplished by reading everything and writing it back without the
    portion you need to "delete".

    If you abstract from a regular stream, you could invent your own
    concepts of "line" or whatever, and operations on it, like reading
    and writing, deleting, skipping, etc. Essentially that's what is
    done by using a "database" as your back end. They have concepts
    of "tables", "records", which can be individually added, deleted,
    changed, etc.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask


    Comment

    Working...