when I try and run my program which successfuly compiles i run into this error
ag715@capa:~$ ./RAT C Parts.txt Output-file
terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 0)
Aborted (core dumped)
through research i believe one of my vectors may be empty. This is how i am adding elements to my vectors
ofstream outputFile;
std::vector<Part> readpartFile(string fileName) //function to read Builders, Customers and Parts text file
{
std::vector<Part> parts;
std::ifstream partsList(fileName);
std::string line;
while (std::getline(partsList, line))
{
line.pop_back(); //removing '.' at end of line
std::string token;
std::istringstream ss(line);
Part part;
std::getline(ss, token, ':');
part.partCode = token[0];
std::getline(ss, part.partName, ':');
std::getline(ss, token, ':');
part.minimum = std::stoi(token);
std::getline(ss, token, ':');
part.maximum = std::stoi(token);
std::getline(ss, token, ':');
part.complexity = std::stoi(token);
parts.push_back(std::move(part));
}
return parts;
}
The string stream fileName is parsed through the main function as an argument, as such
int main(int argc,char* argv[]){
const string fileName = "Parts.txt";
auto customerVec = readcustomerFile(argv[1]);
return 0;
I may add also that previously i did not use command line arguments and the program runs fine. Looking at my readFile functions, can anyone confirm if i am adding to the vector properly or if i am using the correct variables?
Aucun commentaire:
Enregistrer un commentaire