Reading several lines from file

Heya folks,

Im trying to create a function that reads a file (preferably line by line) and use that input to fill a 2D array. Imagina having a file filled but 0's and 1's to indicate an array-position's value. You'd have something like this for example:

1
2
3
4
5
6
7
000000000011100000000010000
100000000011010101000000010
110000000101101000000001110
111000001010000011000000001
111100000101000010000000111
110111001101000000010100011
100011111110010100000011010


The function should now read each line (or even character) individually to fill in the array. I can make my code read the file and evaluate each character individually, but I don't know how to start reading a new line or how to find out if there's a new line. Since the input is in a .txt file I don't think I can simply look for a \n character, am I right?

Just to state my question clearly again: How do I make my code check for a new line when the input is read from a .txt file.

Thank you very much for any and all answers =)
This is similar to what you want: http://www.cplusplus.com/forum/general/22813/
I quickly read through that thread, and I suppose that I should use getline() to well... get the lines? :p But if that is so, does that automatically pick the next line each time it's used in a loop?

Nevermind the above comment, I tried it out with a simple application and also found confirmation that it just reads till the end of the line or a specific delimiter and picks up from there the next time getline() is used.
Last edited on
Topic archived. No new replies allowed.