Read from text file. Set position x y

I can not find anything about it, but I want to ask anyway.

Is it possible to read a character from a text file by setting x and y coordinates?

Here is an example of what I mean (let's say, 4 characters in, and 2 rows down from that point):

my city
my languages
my bone
my boss

The result here is "o" from my bone.

There is something similar for the console I think... "setconsolecursorposition"
A file is just an array of bytes. It doesn't have an inherent spatial structure. If you want it to have one, you'll have to define it yourself.
To read the character in a file at line l column c you have to:
1. Assume that the file is a text file.
2. Read the file line by line (when does a line end?), discarding the lines you don't care about.
3. Skip until line l (what happens if the file doesn't have that many lines?).
4. In line l, read character c (what happens if the line is shorter?).
Last edited on
Any good sources how i can define it myself?
The rest of my post explains how to do it.
If you are allowed to use std::vector you can read all the lines into a vector.
Then you can use [][] to access a single char.
1
2
3
4
5
6
7
8
9
10
  // in the real app you need to real the line from a file
  vector<string> lines =
  {
    "my city",
    "my languages",
    "my bone",
    "my boss"
  };

  cout << "lines[2][2] = " << lines[2][4] << "\n\n";
Topic archived. No new replies allowed.