Mail Archives: djgpp/1998/07/16/06:45:22
Message-ID: | <3008F4AA.35F7@linetap.com>
|
From: | nebo <nebo AT linetap DOT com>
|
Organization: | neboland
|
MIME-Version: | 1.0
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: Reading Lines from .txt files
|
References: | <01bdb026$bfd69980$LocalHost AT default>
|
Lines: | 50
|
Date: | Thu, 16 Jul 1998 08:05:22 GMT
|
NNTP-Posting-Host: | 209.205.49.226
|
NNTP-Posting-Date: | Thu, 16 Jul 1998 04:05:22 EDT
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Jorge Ivan Meza Martinez wrote:
>
> 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" ?
getline() will only read until the delimeter is reached, or
the number of bytes is read, or an EOF.
try..
char linea[257];
archivo_entrada.getline (linea, sizeof(linea), '\n');
--
Nb
nebo AT LTS MajorNet
nebo AT linetap DOT com Internet
I'll stop drinking when I can't pour,
I'll stop standing when I fall over,
I'll stop moving when I pass out,
I'll stop dreaming when I die.
- Raw text -