I\'ve a funny problem with school exercise. I am given latitude and longitude and I have to ensure that it is in right format: \\(\\d+\\.\\d+[NS], \\d\\+.\\d+[EW]\\)>
You can replace E
with X
(for example) in the input string, after running your code you can replace back X
with E
in EW
variable.
char lBracket, rBracket, comma, NS, EW;
int nLat, nLon;
double lat, lon;
std::string inputString = "(51.5N, 0.0E)";
size_t e_pos = inputString.find( 'E' );
if ( e_pos != std::string::npos ) {
inputString.replace( e_pos, e_pos + 1, 'X' );
}
istringstream iss ( inputString );
iss >> fixed >> lBracket >> nLat >> lat >> NS >> comma >>
nLon >> lon >> EW >> rBracket;
if ( EW == 'X' ) {
EW = 'E';
}
lat += nLat;
lon += nLon;
Update: Sorry, didn't see your remark
Only solution I came up with is replace the E with some other letter, which would probably work, but isn't really nice piece of code.
If you want - I'll delete an answer