ifstream fitxer(nomFitxer);
Create a file stream with the last name as an argument. Open a file, come on.
If the file has been opened correctly ...
fitxer >> m_numJornadas;
The declaration of m_numJornadas
is not observed, but, from the following lines, we deduce that it is a int
(or similar, a numeric variable, come on).
That line reads a file number previously opened.
delete[] m_pJornadas;
m_pJornadas = new CJornada[m_numJornadas];
m_pJornadas
is a pointer , of type CJornada *
;
Previous lines release the memory block previously pointed to by m_pJornadas
, and assign a new memory block, capable of containing m_numJornadas
(whose value we previously obtained from the file).
fitxer >> m_pJornadas[i];
Inside the loop, filling the previously reserved memory block with the CJornada
s data that we are obtaining from the file.
In summary: open the file, read the number of elements to be read, assign a memory for that number of elements, and read and place them in the above memory block.
We had a list of elements, and replaced it with a new list of elements.
EDITO
To respond to comments:
What tells you which line of the document to read?
Start at the beginning; it reads right after opening it, so it starts with the byte 1 of the file.
The first reading, unless the operator ifstream::operator>>( )
is rewritten, reads an integer; Size? Until it reaches \n
.
How often does it go down to the next line?
As you are reading CJornada
s, we do not know ; we do not know if it is a typedef
of some basic type, or a class of its own. In the latter case, you may have defined the ofstream::operator>>( std::ofstream &, CJornada & )
, so you can read the way that class considers convenient: byte to byte , line by line (up to the \n
), 300 in 300 bytes , ...