Question

I am getting an error and I can't figure out why, below is my code:

// reads a file and stores data to a dynamic memory aray
string readFile(string filename, string** list, int size){
        *list = new string[size];
        ifstream file(filename);
        string line;
        for (int i = 0; i < size; i++){
            getline(file, line);
            *(list + i) = line; // getting an error at this line
        }

        file.close();
        return **list;
    }
Was it helpful?

Solution

*(list + i) = line; // getting an error at this line

Should be:

*(*list + i) = line; //because *(list + i) is of type string*, not string
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top