I'm new to C++ and I've playing around with some code but have come up with a problem.
I have a text file that i want to read into a 2D array of strings. The text file is just a bunch of words, one word per line.
My problem is i don't know how to read a line from the text file, put it into a spot in the array and then move onto the next line in the file and place that word in the next spot of the array. Obviously this could also be done in a 1D array but for the purpose of this exercise it needs to be 2D, although that is not the hard part, as it stands i wouldn't even know how to read my lines into the 1D array (I'm assuming it is exactly the same).
So far i only know how to open a file, it is a start i guess.
Thanks in advance for any help.
EDIT: ok so i did some playing around with the code i had (which i got from a google search) and figured out what i was doing wrong...i think.
getline(txtfile, array[x][y], ' ');
is what i had, i didnt know what the last argument (the space) was for but i left it in. i decided to change it to:
getline(txtfile, array[x][y], 'a');
and found that it seemed to read everything up until it found the letter a. so i changed it to
getline(txtfile, array[x][y], '\n');
and this turned out to be what i wanted, stopping once it got to a new line. hope this helps anyone else with similar issues :D