Re: Help with c++ arrays and file reading
Simply write three input >> statements reading the different data fields into different arrays, all of which are indexed by [i].
BTW, the first line of your input file contains a record count. Either read it first and use it for the terminal condition of your loop, or read and discard it, and then read the records until you reach EOF. If you do neither of those, your program most likely gets screwed up.
HTH
Re: Help with c++ arrays and file reading
But how would I read the statements that are further in the file?
I know for the words I can just put char name[i] and put those into an array but how do I get the two numbers on the same line into a different array
Re: Help with c++ arrays and file reading
What about simply using this:
Code:
input >> an_array[i];
input >> another_array[i];
input >> yet_another_array[i];
?
Whitespace is a default separator when reading from cin that way, and both ' ' and '\n' are whitespace.
Re: Help with c++ arrays and file reading
Ohhhh alright thank you! Sorry I'm dumb. >.<
Re: Help with c++ arrays and file reading
Actually when I do that my array keeps coming out as huge numbers. Like nothing is stored.
Re: Help with c++ arrays and file reading
Oops! I failed to notice that you are using eof() the wrong way in your original post. If you opened the file successfully, eof() will return the boolean value false, which is converted to integer 0. Therefore, the terminal condition of the loop will be true before the very first iteration and as a consequence you actually read nothing.
Using eof() that way isn't a good idea anyway: It will only become true after you actually attempt to read past the end of file, and thus you will read exactly one bogus record at the end. So you are better off to use the record count in the first line of the file as a criterion, which already was one of the options I suggested in post #2.