Read a single value from a file

Hi guys,
I'm new to c++ programming and I'm having some issues about reading from a .txt file. I need to read only one value inside a file which is full of other values which I don't care about right now. For exemple, assume that i need the number which is on the third line and the second column, in a file like this:

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16

Which in this case is 10.
How con I extrapulate it?
You could read the first 9 values in a loop and discard them.
Finally you read the 10th number.
No man I just wanted to input the numbers of line and column of the matrix element that i need (3 and 2 in the exemple) and then get what i want in output. Maybe to fulfill a vector with all the numbers and the take the ((3x2)-1)th element could be an option? Btw thank you so much for the advice.
Last edited on
No man I just wanted to input the numbers of line and column of the matrix element that i need (3 and 2 in the exemple)

With all respect, that, for your particular file, is exactly what @Learner2 has explained how to do.


Show your actual code, show your actual input file, and explain what you intend to do with any data in it at any point in running the program.

You might want to state your assignment; (the original version, not your re-wording of it).
i need the number which is on the third line and the second column

Read each line from the file, discarding the first two.

With the third line parse out the individual data elements, discarding the first entry. Store the second.

Assignment solved.

Except for writing that code thingy. That you need to do.
Topic archived. No new replies allowed.