- #1
Saladsamurai
- 3,020
- 7
I am not sure how to do this:
I have a text file that I have assigned to an ifstream object. The text file looks something like:
I want to read the data into an array of structs. So I need to determine how many headers there are if I don't know in advance.
I am not sure of the best way to do this? I thought that I could just cin the data into a variable while incrementing a counter variable until I encounter a newline character. But I don't know if cin will actually read in a newline or if it will just skip over it? I think the latter.
Any thoughts?
I have a text file that I have assigned to an ifstream object. The text file looks something like:
Code:
Header1 Header2 Header3 ... HeaderN
data1 data2 data3 ... dataN
.
.
.
I want to read the data into an array of structs. So I need to determine how many headers there are if I don't know in advance.
I am not sure of the best way to do this? I thought that I could just cin the data into a variable while incrementing a counter variable until I encounter a newline character. But I don't know if cin will actually read in a newline or if it will just skip over it? I think the latter.
Any thoughts?