Reading multi data type CSV

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).



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <string>
#include <array>
#include <sstream>
using namespace 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;
}



the data will look like

Luton,Town,211228,51.87967,-0.41748
Maidstone,Town,107627,51.26667,0.51667
Topic archived. No new replies allowed.