I've got some input like this: (50.1003781N, 14.3925125E)
which is stored in const string & input
. What I'm trying to do is to extract the brackets, get the number representing the GPS coordination - 50.1003781, save N and do the same for the second coord.
So here goes my code:
istringstream iStream(input);
char brackets[2]; //To store the brackets
char types[2]; //To store if it is N/S or W/E
char delim; //To store ","
double degrees[2];
iStream >> brackets[0] >> degrees[0] >> types[0] >> delim;
//The delim loads the "," and here goes my problem with whitespace which is next
iStream >> degrees[1] >> types[1] >> brackets[1];
But it fails on loading degrees[1]
, it loads zero and tellg()
says -1 probably because of whitespace after the comma. The parsed string should be like this:
cout << brackets[0]; // "("
cout << degrees[0]; // "50.1003781"
cout << types[0]; // "N"
cout << delim; // ","
cout << degrees[1]; // "14.3925125"
cout << types[1]; // "E"
cout << brackets[1]; // ")"
I've tried skipws and noskipws but with no effect. Can anybody help, please? Thanks a lot.