嗨我正在使用GPS输出。为了更准确,我正在使用$ GPRMC输出。现在,我得到的输出为以下形式:使用C++输出GPS输出
$GPRMC,225446,A,4916.45 N,12311.12 W,000.5,054.7,191194,020.3 E,*68"
此输出构成的时间,拉特,长材,在海里的速度,信息关于课程,日期,磁场变化和强制性检验。
现在我得到的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;
}
请重新考虑你的东西往往被认为使用不好的做法:['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