Home > Back-end >  File operations
File operations

Time:10-05

Have a text data file

1 2 3 4
5 6 7 8
. 1000 lines


After more than one thousand lines need to be added in line one thousand, at the same time to delete the first line of data,
It means that this file is constantly add, delete the first line, total number of rows to keep in line one thousand

How to deal with?

CodePudding user response:

This is not difficult to ah, hypothesis 1 row 1 KB, 1000 lines of up to 1 MB

CodePudding user response:

Delete files after reading the first line content increased the last line and then written to cover

CodePudding user response:

Covered writing good trouble, each time to read a lot of data, and what the method is simple point?

CodePudding user response:

Simple and convenient with TStringList directly,,
Objects created StringList
//
TStringList * LST=new TStringList;
//load the file
LST - & gt; LoadFromFile (" name ");
//remove the first line
If (LST - & gt; The Count & gt; 0) LST - & gt; Delete (0);
//add a line at the end
LST - & gt; Add (" to Add data ");
//write to files
LST - & gt; SaveToFile (" name ");
//clear
The delete LST.

CodePudding user response:

If the data is not important, you can write a when the program exits

CodePudding user response:

Support the StringList
Objects created StringList
//
TStringList * LST=new TStringList;
//load the file
LST - & gt; LoadFromFile (" name ");
//remove the first line
If (LST - & gt; The Count & gt;=1000) {for (int I=0; i//add a line at the end
LST - & gt; Add (" to Add data ");
//write to files
LST - & gt; SaveToFile (" name ");
//clear
The delete LST.
  • Related