Re: file read problem
On Dec 3, 4:49 pm, "Art Cummings" <aikia...@gmail.com> wrote:
Thanks Jim, it doesn't do that with my file. It reads the
entire file. I wonder if there is something odd with the file
i'm using.
What do you mean by "reads the entire file"? As Jim Langston
has pointed out, your code will hit the _getch() function
(whatever that does) every 25th line. On the other hand,
depending on its size, the file may have been physically read
and buffered; most implementations read files in more or less
large blocks (one or two KB seems to be a frequent size).
(A cleaner implementation would probably use nested loops:
while ( inFile ) {
std::vector< std::string > lines ;
std::string line ;
while ( lines.size() < maxLines
&& std::getline( inFile, line) ) {
lines.push_back( line ) ;
}
// process lines, or whatever...
// note that lines may be empty here, which
// may require special handling.
}
.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34