Extract Character from file

Oki, i'm using fstream.getline to extract characters from a file.

Now, here's the problem:

Suppose i have a file named lel.txt containing:
123
321

when i use myfile.getfile(123, 4);
should i use seekg to set the next line or no?
A mysterious question. The heading says "extract character" - which i assumed meant a single character at a time. Then there is mention of getline() and lastly a mysterious getfile() function.

If I took a guess, I'd say getline() would move the file position to just after the newline character, so no, you don't need seekg. The exception would be if the line was longer than the buffer size, in which case the getline() if used properly, would leave the remaining characters of the line unread, so you might need ignore() to skip past them.

http://www.cplusplus.com/reference/istream/istream/getline/
If the line contains more than the buffer can hold you'll also need to clear() the stream error before the ignore().

But why are you using getline() to retrieve "numbers" the extraction operator>> would probably be a better choice.
Topic archived. No new replies allowed.