option 4 crashes with a wrong input

it crashes after city not found
so here is the code
http://pastebin.com/Vgy5dKt5
if you run and read file of cities into it so maybe like if your file contained
Calgary 51.1 -114.0167
Vancouver 49.1833 -123.167
Winnipeg 49.9 -97.2333
Ottawa 45.3167 -75.6667
Moose_Jaw 50.3333 -105.55
and you enter that files names it load and then you choose option 4 and then enter a city that doesn't exist it crashes :|
how to fix it
line 230 cout << cities[findLocation(citynm, cities)] << endl;
if you dont find the city, findLocation(...) will return -1, so you try to get cities[-1].
index out of bounds.

check the return value before you try to get the city, or use cities.at(), it will throw an exception if the position
is not valid.
Topic archived. No new replies allowed.