Newb here... taking a C++ class on data structures. I am making a program that takes a list of chores from a text file and stores them in a dynamic array.
//In header/ In class:
private:
/* var to keep len of list */
int len = 99; // Not sure what to set this to or if I need to even set it.
/* add appropriate data structure to store list */
string *arr = new string[len];
//In .cpp:
ListOfChores::ListOfChores(string fileName) {
ifstream file(fileName, ifstream::in);
string line;
if (file.is_open()) //Checking if the file can be opened
{
while (!file.eof()) // To get all the lines.
{
getline(file, line); // Gets a single line
arr[len] = line; // Store a line in the array
len++; // Increases the array size by one
}
file.close(); // Closes file
}
else cout << "Unable to open file" << endl; // Gives error if the file can't be opened
}
But I am getting an error for storing a line in the array. It says "Access violation reading location." There is another function executed in the main.cpp for printing the lines.