I need to implement a version of the shortest path (of sorts) with about 100 cities.
I only need help with the first bit: get the data in.
Duoas has already helped me with this (but at the moment it seems to be doing nothing).
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <string>
#include <array>
#include <sstream>
usingnamespace std;
struct City
{
string name;
double latitude;
double longitude;
};
//
//
istream& read_city(istream& ins, City& city)
{
// Get the line into a string
string s;
getline(ins, s);
// Now we'll parse the string into fields
istringstream ss(s);
getline(ss, city.name, ',');
ss >> city.latitude;
ss.ignore(1000, ',');
ss >> city.longitude;
// If something went wrong, make sure that the error gets reported
if (!ss) ins.setstate(ios::failbit);
// Return the input string so that the user can test it for good()
return ins;
}
vector <City> cities;
int main()
{
City city;
ifstream f("GBplaces.csv");
while (read_city(f, city))
{
cities.push_back(city);
}
//if (!f.eof())
//{
// cerr << "Hey, invalid input!\n";
// getchar();
// return 1;
//}
getchar();
return 0;
}