A
A
asdqwe13132021-06-09 20:37:41
C++ / C#
asdqwe1313, 2021-06-09 20:37:41

Working with a file through a c++ function?

Good afternoon!

Tell me how to write a function for reading a line from the number N to the number M, so that it can later be used to read from M + 1 to K. I implemented the solution, but it requires you to go to the beginning of the file, then through the GoToLine (M + 1) function ) go to M+1 line, and then from M+1 to K.

I want to be able to use this function like this - GetMN(FILE,N,M);GetMN(FILE,M+1,K);

Implemented now - GetMN(FILE,N,M); FILE.CLEAR(); FILE SEEKG(0); GoToLine(M+1); GetMN(FILE,M+1,K);

void GetMN(std::fstream& file,int n,int k){

..

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-06-09
@wataru

You need a dumb function that reads K lines and that skips K lines.
Then your code becomes Skip(N-1), Read(M-N+1), Read(K-M+1) and reads the file exactly once.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question