getline and deleteline

R

Ron Eggler

Hi,
I am reading out a text fileusing following lines:
[C++]
ifstream ifs (RECORD_FILE, ifstream::in );
while( getline(ifs,recordStr) ) { // 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::eek:ut" when
defining my handle. But I didn't find a method to delete a line.

Thanks for your help!
 
V

Victor Bazarov

Ron said:
I am reading out a text fileusing following lines:
[C++]
ifstream ifs (RECORD_FILE, ifstream::in );
while( getline(ifs,recordStr) ) {
// 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::eek:ut" 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top