-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_graph.cpp
45 lines (34 loc) · 863 Bytes
/
read_graph.cpp
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
#include <iostream>
#include <fstream>
using namespace std;
int main() {
cout.precision(17);
// Placeholder
string str = "";
ifstream input;
input.open("graph1000.txt");
if (!input)
{
cerr << "Failed opening graph1000.txt" << endl;
exit(1);
}
int i = 0;
while(i < 1000)
{
cout << "Index " << i + 1 << endl;
// ignore(<number of characters to ignore until delimiter seen>, <delimiting character>)
input.ignore(5, ':');
input.ignore(1, ' ');
// The third argument ',' is delimiter. When used, getline stops reading right there
getline(input, str, ',');
double latitude = atof(str.c_str());
cout << "X: " << latitude << endl;
input.ignore(1);
getline(input, str);
double longitude = atof(str.c_str());
cout << "Y: " << longitude << endl;
cout << endl;
i++;
}
return 0;
}