I have a text file that I would like to read a specific line from. All lines have the same amount of characters (one 3-digit number on each), and I would like to read from a specified line. Is there a way to do this?
I'd suggest using getline() in a loop to read (and discard) the required number of lines to reach the required data. Then perhaps use atoi() to convert the text of the line into an int. Or use a stringstream to extract the number from the line.
Alternatively, if you are certain that each line contains just a number and nothing else (apart from some possible whitespace), then forget about reading lines. Just read a number repeatedly using a loop, in order to ignore the first n-1 values.
So, you have a hallway with a bunch of doors numbered 1, 2, 3, ... and you want to knock on door 5. To get to door 5, you have to walk past (ignore) doors 1 through 4. What does ignore mean? Just don't knock on them!
To ignore a line, read it in but don't do anything with it.
Well, if you're going to hard-code for the size of each line and ignore the possibility of whitespace, then I suppose that's a valid solution...but I recommend not using it.