www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/15/15:35:38

Reply-To: "Jorge Ivan Meza Martinez" <jimeza AT usa DOT net>
From: "Jorge Ivan Meza Martinez" <jimeza AT usa DOT net>
To: <djgpp AT delorie DOT com>
Subject: Reading Lines from .txt files
Date: Wed, 15 Jul 1998 14:28:30 -0500
Message-ID: <01bdb026$bfd69980$LocalHost@default>
MIME-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019