//main.cpp
#include"city.h"
#include<string>
#include<iostream>
#include<vector>
usingnamespace std;
vector <int> readFileTask (string fname);
int main()
{
vector<int> int_vec;
vector <int> vector1;
string fname;
bool fileOK = false;// test the file whether it can be opened or not
while(!fileOK){// while loop gets user input while try and catch handle file error.
try
{
cout << "Enter the name of the file to be opened: ";
cin>> fname;
int_vec = readFileTask(fname);
fileOK = true;
}
catch (invalid_argument & e)// catched invalid argument.
{
cerr << "invalidargument_error: " << e.what() << endl;
}
}
and this what i need to do
how do i improvise it to meet this paticular requirement
The user should be prompted to enter the name of a file of cities. The file's contents should be read into the program's city vector, replacing its contents, if any. If the file does not exist or is formatted incorrectly the program's city vector should not be changed and the user should be prompted for a new file name. The first function will read a file of cities into a vector of cities and should have a string parameter that represents the name of the file to be opened and should return a vector of cities (vector <City>). This function should throw errors if the file cannot be opened or if it is formatted incorrectly. The second function would be responsible for requesting the file name and handling any errors.
File Format
Each city is recorded in a single line of the file with its name, latitude and longitude data separated by spaces. Here is the data from a small sample file, which you can find here. The format is name latitude longitude.