In my C++ program I have a text file that I read line by line into a vector
called flights
and afterwards I search for some strings inside this vector of strings, but unfortunately if I don't find any matches I get the following error
A flights vector has this format:
EMA CDG BritishAirways 120 100
CDG VIE AirFrance 120 100
EMA VIE BritishAirways 150 300
EMA CDG AirFance 130 80
GRO FFF Rayanair 130 80
FFF HHH AirItalia 100 50
Unhandled exception at at 0x769E4598 in OOP project.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0052F0F0.
I think I have found that the error must be somewhere in my connectedJourney
functon:
/* The following code searches for journeys that have a connection. so the use 2 different flights
First of all looks for flights that are leaving from the same airport that the user indicated and stores the flight details in "deptMatches".
Secondly it will look for flights that have the destination that the user indicated and stores it in "destMatches".
Thirdly it will check if the destination code of any of the deptMatches matches the departure code of any of the destMatches.*/
vector < vector < string >> connectedJourney(string airpCode1, string airpCode2, vector < string > flights) {
vector < vector < string >> rawMatches;
vector < string > deptMatches;
for (unsigned int f1 = 0; f1 < flights.size(); f1++) {
//store all the fligths that match the departure airport into deptMatches
if (airpCode1 == flights[f1].substr(0, 3)) {
deptMatches.push_back(flights[f1]);
}
}
vector < string > destMatches;
for (unsigned int f2 = 0; f2 < flights.size(); f2++) {
//store all the fligths that match the departure airport into deptMatches
if (airpCode2 == flights[f2].substr(4, 3)) { //the call stack says the error is at this line
destMatches.push_back(flights[f2]);
}
}
if (deptMatches.size() == 0 || destMatches.size() == 0) {
// check if there won't be any matches
throw noEntryFound();
} else {
vector < string > cj_Matches; //connected journey matches
for (unsigned int g1 = 0; g1 < deptMatches.size(); g1++) {
for (unsigned int g2 = 0; g2 < destMatches.size(); g2++) {
if (deptMatches[g1].substr(4, 3) == destMatches[g2].substr(0, 3)) {
//if the arrival place of the first flight matches the departure place of the first flight then the details of both flights are saved into a vector within another
rawMatches[0].push_back(deptMatches[g1]);
rawMatches[1].push_back(deptMatches[g2]);
}
}
}
return rawMatches;
}
}
I have also uploaded my whole project here if it is useful: https://drive.google.com/folderview?id=0B-VbnRtajCWIfmFxMk5UUncwSkNzNm8tT2xrU0hDM29kbzg4TUFKODJSUExMTV9oVDFncjA&usp=sharing