For a clustering program I am writing, I need to read information from a file. I am trying to read coordinates from a file with a specific format:
1.90, 2
0.0, 4.01
6, 1.00
Unfortunately, I have not been able to do this, because of the newlines and dots that are present in this file. Neither of the following two functions work, even though the filestream is "good":
std::vector<Point*> point_list_from_file(std::ifstream& ifstr) {
double x, y;
char comma;
std::vector<Point*> point_list;
while(ifstr >> x >> comma >> y) {
point_list.push_back(new Point(x,y));
}
return point_list;
}
std::vector<Point*> point_list_from_file(std::ifstream& ifstr) {
double x, y;
char comma;
std::vector<Point*> point_list;
while(ifstr >> x >> comma >> y >> comma) {
point_list.push_back(new Point(x,y));
}
return point_list;
}
I have no idea how to fix this and any help is greatly appreciated.