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're essentially looking at a parse problem. operator>>(istream&, string&)
is a very simplistic parser that just tokenizes on whitespace.
If your format specification is strict enough, and you should reject (51.5N , 0.0E)
(extra space before comma) then just don't extract the comma. Instead, directly after extraction you should check that nLat
contains the trailing comma and remove it. You no longer need >>comma
.
If you must support optional whitespace anywhere, it may help to preprocess the string by inserting an extra space before and after the comma (unconditionally). If there already was a space, there will now be two. That's no problem as whitespace skipping will skip any amount.