Reading Text file and filling a 2D array

i need some serious help with my program! i need to read a file (test.txt) that has a 5x5 grid with numbers each followed by a zero! like so

01 12 11 09 10
11 12 11 09 10
31 12 11 09 10
51 12 11 09 10
06 12 11 09 10

read the file and put it into a 2d array to later calculate some things! ive gotten the rest of the algorithm the only thing left is to import the file and convert the the numbers to ints and put them in the array so i can use them. this is all i got and i dont know where to go from there/


//open file
ifstream inFile;
inFile.open("test.txt");

// Checking
if (inFile.is_open()) {
//get a line

cout << "File Read"<< endl; // !Working
}
else{
cout << "Not Read"<< endl; // !Working
}
Here is a simple read in with ifstream for you to use.
Read the comments.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <fstream>
#include <iostream>
// Other headers

int main()
{
    std::ifstream fin("test.txt");

    int grid[5*5] // Array to hold grid. Single dimension.

    if (!fin.is_open ()) // ALWAYS TEST IF FILE EXISTS
    {
        std::cout << "File not found. Check executable directory for the file.\n\n"
        return 1;
    }

    for (int i = 0; i < 25 && fin.good(); ++i) // Less than 25 elements, and ifstream is still good.
    {
        fin >> grid[i];
        // Reads Left to right, top to bottom.
    }

    std::cout << "File Read." << std::endl;
}
any way of doing this whit a 2D array?
Topic archived. No new replies allowed.