I'm trying to read an inventory system into a struct array. When I call the function and it gets to the first line I try and write data into the array, I am given the error:
Unhandled exception at 0x777CA932 in Lab 09.exe: Microsoft C++ exception: std::out_of_range at memory location 0x00F3DC68.
Here's the struct:
struct inventory {
int record;
string toolname;
int quantity;
double cost;
};
Array declaration:
inventory unsortedArray[100];
Here's the function (assume first line of file is 83 #Electric Sander# 7 57.00):
void fillArray(inventory unsortedArray[]) {
ifstream file;
string line;
string delim = "#";
stringstream ss;
file.open("records.txt");
int i = 0;
while (!file.eof()) {
getline(file, line);
unsigned first = line.find_first_of(delim);
unsigned last = line.find_last_of(delim);
unsortedArray[i].toolname = line.substr(first, (last - first) + 1);
line.erase(first, (last - first) + 1);
ss << line;
ss >> unsortedArray[i].record;
ss >> unsortedArray[i].quantity;
ss >> unsortedArray[i].cost;
i++;
}
file.close();
}