次のような入力があります。(50.1003781N, 14.3925125E)
これは に保存されていconst string & input
ます。私がやろうとしているのは、ブラケットを抽出し、GPS 座標を表す番号 (50.1003781) を取得し、N を保存して、2 番目の座標に対して同じことを行うことです。
だからここに私のコードがあります:
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];
しかし、読み込みに失敗し、おそらくコンマの後の空白のためにdegrees[1]
ゼロを読み込み、 -1 と表示されます。tellg()
解析された文字列は次のようになります。
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]; // ")"
skipws と noskipws を試しましたが、効果がありませんでした。誰か助けてくれませんか?どうもありがとう。