I am currently making a small console game to get to grips with the basics of the basics in C++ and have encountered the following issue : I'm creating an ifstream in order to read a .txt file, the first two lines correspond to integers, and the third is for a grid of blocks (using a 1D array) of dimensions those two integers.
However, the getline call seems to read the whole file at the first pass. Looking this issue up, it seems to be some trouble with encoding endline statements in text editors. Does anyone know more about this ? I use Windows 7 basic text editors such as Notepad and Notepad++. Also, from what I've seen, this issue is pretty uncommon ; I'd have expected it to be a lot more common as it's pretty much the first time I've tried reading from a file.
P.S : I'm not new to programming, just new to C++.
P.P.S : Also, if you see any bad C++ programming practices in there, please point them out.
In your while loop you don't increment the variable "i".
That could be a problem. Usually variables named 'i' are simple counts/indexes, but yours appears to represent state, and your state doesn't change. (In which case line 10 does not output the entire file, but multiple iterations of the loop invoke line 10 repeatedly until input fails.) This would be easily observable with a debugger.