ads@gateway.mitre.org (Alexas D. Skucas) (03/08/91)
I'm a bit confused about how to skip to the next line when using input streams in C++. For example, if I am reading from a file that has ten entries on a line and decided to skip to the next line after reading only two of the entries, how do I do it? Currently I use cin.get(buf,1000) which puts everything into buf (up to 1000 characters) until it hits a new line character. Is there a more elegant way to do this? I don't like having to use a buffer since that eats up memory space. Thanks for any advice Alex ads@gateway.mitre.org
garnett@savage.bellcore.com (Michael Garnett) (03/08/91)
In article <1991Mar7.211045.16370@linus.mitre.org>, ads@gateway.mitre.org (Alexas D. Skucas) writes: [...] |> |> For example, if I am reading from a file that has ten entries on a line |> and decided to skip to the next line after reading only two of the |> entries, how do I do it? |> [...] |> Alex |> ads@gateway.mitre.org use the ignore method of the istream class: ifstream F("somefile.txt"); /* code that reads the 2 entries ... */ F.ignore(255, '\n'); // eat up to 255 characters and stop after // extracting the '\n' // the use of 255 is arbitrary...I assume that // your text lines are going to be less than 255 // characters long. is that what you wanted? ------------------------------------------------------------------------ ********* Michael S. Garnett ** o ** Information Networks Research ** _- -_ ** Ph: 201-829-4591 ** / \ ** Internet: garnett@thumper.bellcore.com * | | * UUCP: ...!bellcore!thumper!garnett ** | | ** ** /_______\ ** // I speak for only myself, and NOT any company or ** o ** // organization directly or indirectly associated with ********* // Bell Communications Research