Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!udel!rochester!pt.cs.cmu.edu!ROUGE.EDRC.CMU.EDU!vcr From: vcr@ROUGE.EDRC.CMU.EDU (V C Ramesh) Newsgroups: comp.lang.c++ Subject: help with "get" Keywords: "get", fgets, newline skip Message-ID: <10740@pt.cs.cmu.edu> Date: 13 Oct 90 01:22:49 GMT Reply-To: vcr@cs.cmu.edu (V C Ramesh) Organization: Carnegie-Mellon University, CS/RI Lines: 48 I am new to C++. I am trying to make "get" provide the same functionality that "fgets" provides in C...namely, to read in successive lines of input for processing. However, I am having problems with the newline character, which, get(char *) skips on the first scan, and on the next scan sees as the first character, and reads in an empty line. Thus only the first line is read in correctly, and all the other lines are skipped. I have enclosed a test code and typical output. Is "get" the right function for my purpose ? If so, how can I get over this '\n' problem ? In C++, which function does one normally use to read in a file, and process each line ? Thanks for any help, Ramesh vcr@cs.cmu.edu ---------------------- TEST CODE --------------------- main(int argc, char* argv[]) { filebuf fin; if (fin.open(argv[1],input) == 0) error("cannot open input file", argv[1]); istream from(&fin); char linebuf[80]; while(from.get(linebuf,80,'\n') && !from.eof()) { cout << "Read in this line: " << linebuf << "\n" ; getchar(); } } ------------ Input file --------- thanks to everyone who responded. I moved the function... including string.h... ...... ---------------- Output Read in this line: thanks to everyone who responded. [CR] Read in this line: [CR] Read in this line: [CR] ^C (I give up) -------------------