Mail Archives: djgpp/1998/07/15/15:37:57
Hello to everyone,
I don't know if my question fits here but I hope,
I need to read lines from an ascii file, I use something like this:
#include <iostream.h>
#include <fstream.h>
char linea[70];
ifstream archivo_entrada ( filename );
if ( archivo_entrada.fail () ) { cerr << "fallo en archivo_entrada " <<
filename << endl; return ( false ); }
while ( !archivo_entrada.eof () )
{
archivo_entrada.getline ( linea, sizeof ( linea ) -1 );
/** asegura que la cadena tenga fin */
linea [76] = '\0';
cout << linea << endl;
}
archivo_entrada.close ();
I open a ifstream and read lines with getline method but the problem is the
length of the line, getline reads a const number of bytes, in this case
(70)-1; but what if I don't know how many bytes I want to read, worse than
that, if the line has more that (70)-1 the program dies.
How do you do things like this ?
How is the best "DJGPP way" ?
I prefer C++ but C is useful to me too.
thanks to all.
jorge ivan meza martinez
http://members.xoom.com/THP
jimeza AT usa DOT net
- Raw text -