こんにちはGPS出力を使用しています。私は$ GPRMCの出力を使用してより正確に私は働いている。今、私が手出力は次のような形式である:C++を使用したGPS出力の操作
$GPRMC,225446,A,4916.45 N,12311.12 W,000.5,054.7,191194,020.3 E,*68"
この出力は、時間、ラッツ、long型、ノットの高速、もちろんに関する情報、日付、磁気変動と必須のチェックサムを構成しています。今、私はHHMMSS形式で時刻を取得してい
。私はhh:mm:ss形式でそれを欲しい。 プラス私は4916.45 Nとして経度を取得しています。私は49度16'45 "として取得したいと考えています 123度11'12"と緯度。私は初心者ですので、実際にフォーマットを変換する方法はわかりません。以下のコードを添付しました。
#include<iostream>
#include<string>
#include<sstream>
#include<stdio.h>
#include<conio.h>
using namespace std;
int main()
{
std::string input = "$GPRMC,225446,A,4916.45 N,12311.12 W,000.5,054.7,191194,020.3 E,*68";
std::istringstream ss(input);
std::string token;
string a[10];
int n = 0;
while (std::getline(ss, token, ','))
{
//std::cout << token << '\n';
a[n] = token;
n++;
}
cout << a[0] << endl << endl;
cout << "Time=" << a[1] << endl << endl;
cout << "Navigation receiver status:" << a[2] << endl << endl;
cout << "Latitude=" << a[3] << endl << endl;
cout << "Longitude=" << a[4] << endl << endl;
cout << "Speed over ground knots:" << a[5] << endl << endl;
cout << "Course made good,True:" << a[6] << endl << endl;
cout << "Date of Fix:" << a[7] << endl << endl;
cout << "Magnetic variation:" << a[8] << endl << endl;
cout << "Mandatory Checksum:" << a[9] << endl << endl;
_getch();
return 0;
}
ことが多いと考えられるものの使用を再考してください: -
は経度を解析し、私は正規表現を示唆して緯度するには、私は、これは正規表現が正しいですnotsayingています、それはあなたが提供したデータを解析し、悪い習慣:['using namespace std;'(http://stackoverflow.com/q/1452721/1171191)と['endl'](http://chris-sharpe.blogspot.co.uk/2016/02 /why-you-shouldnt-use-stdendl.html)(説明へのリンクです)。 – BoBTFish