I have a text file containing numbers. the first two numbers are the x and y size of the map im trying to create (for a game), and the rest are the IDs of the tiles that make up that map.
my question is, if i read the fist two variables into my class fields XMapSize and YMapSize like so:
and have it begin from the point after the the two variables that were assigned to XMapSize and YMapSize? Or does it reset from the beginning? Ive never used txt files/ifstream in any of my games so this is all new to me, and i couldn't infer the answer from the documentation on this site.
----------------------
question 2:
i'd like to use a while loop to check for !.eof() instead of relying on making sure the mapsize numbers are exactly right, but i can't get it to work with the for loops necessary to fill the multidimensional array. If i have the for loops INSIDE the while loop, then the !.eof() is unecessary because it won't load anything once i/j > XMapSize/YMapSize in the for loop! any advice on that?
a1. It would work, except that line 3 of the first snippet should have >> instead of ,
a2. Append the condition to the for loop conditions. for(int i = 0; i < size && condition; i++) .... However if you replace "condition" with "!inputStream.eof()" you may have some problems with the last number. Instead "condition" should be "inputStream". If there are any errors stream object will evaluate to false here. The possible errors are file not found, attempt to read after eof or trying to convert words to numbers (maybe something more. my point was that it is not only eof)