S
S
SatanistArtem2018-10-18 20:16:55
C++ / C#
SatanistArtem, 2018-10-18 20:16:55

How to pass file path to constructor?

I created a library, the constructor must accept a string (path to the file), but an error occurs at the compilation stage:
5bc8bfd23b8ed933816229.png
constructor code:

Grid::Grid(string path_to_grid_txt){

    ifstream grid_txt(path_to_grid_txt);

    grid_txt >> height;
    grid_txt >> width;

    grid_nodes = new node * [height];
    for(int i = 0; i < height; ++i){

        grid_nodes[i] = new node [width];

        for(int j = 0; j < width; ++j){

            grid_txt >> grid_nodes[i][j].pass;

            grid_nodes[i][j].coordinates.x = j;
            grid_nodes[i][j].coordinates.y = i;
            grid_nodes[i][j].n = i * width + j;
        }
    }
}

I pass it like this:
int main()
{
    string a;

    cin >> a;

    Grid st(a);

    return 0;
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question