Read and display character located at a 26*26 grid

This is a personal project and I'm quite a noob into c++. What I'm trying to achieve is a small program able to read a character located at a specific X & Y coordinates in a file.
For example:

1 2 3 4 5
----------
a| a y o d f
b| z l s q r
c| t a e p n
d| r s d o a
e| q o y h k

I want to be able to read and display the contents of C1, E4, D5, C5, E5 & B3 or any other location given by the user's input.

Thanks in advance.
1) Read in the file into a 2 dimensional array.
2.1) Read user input.
2.2) Validate input.
2.3) Use coordinate to access values of your 2 dimensional array.
2.4) Retry from 2.1 if user doesn't quit the session.
Same idea, but use a vector of strings.
The usual array syntax array[row][col] can be used.

1
2
3
4
5
6
7
8
    vector<string> array;
    ifstream fin("data.txt");
    string temp;
    
    while (getline(fin,temp))
        array.push_back(temp);

    cout << array[2][3] << endl;

Needs validation/error checking - did the file open, how many lines were read, what is line length etc.

http://www.cplusplus.com/reference/vector/vector/push_back/
http://www.cplusplus.com/reference/string/string/getline/
http://www.cplusplus.com/reference/vector/vector/size/
http://www.cplusplus.com/reference/string/string/size/
Last edited on
thank you both! this was very helpfull
Topic archived. No new replies allowed.