www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/15/01:18:30

From: anonymous <naga4321 AT delanet DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Getline help
Date: Mon, 12 Jan 1998 19:58:54 -0800
Organization: PDN/Chatlink
Lines: 31
Message-ID: <34BAE67D.5DA1@delanet.com>
Reply-To: naga4321 AT delanet DOT com
NNTP-Posting-Host: realnews.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I receive a run time error in HEX when I attempt to read a data file
consisting of 2 lines with the following code.

Any help on proper use of the getline routine would be appreciated.

 (note: the code extracts the first line of the file without error if I
don't use the     second getline request to try to get the second line
in the file).

Please reply to my email address.


#include <iostream.h>
#include <fstream.h>

int main()
{

ifstream inFile = "test3.dat";   //test3.dat contains 2 lines for input

char * ptr_line1;
char * ptr_line2;

inFile.getline(ptr_line1,50,'\n'); 
inFile.getline(ptr_line2,50,'\n');   

cout << ptr_line1 << endl;
cout << ptr_line2 << endl; 

return 0;
}

- Raw text -


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