Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : 定義主控台應用程式的進入點。
- //
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cctype>
- using namespace std;
- int main()
- {
- fstream file;
- file.open("C:\\nmea_sample.txt", ios_base::in);
- if (!file)
- {
- cout << "開起失敗" << endl;
- }
- string temp, checkstr = "$GPGGA";
- while (!file.eof())
- {
- bool isGPGGA = 0;
- file >> temp;
- if (temp.find(checkstr) != string::npos)
- {
- cout << temp << endl;
- isGPGGA = 1;
- }
- if (isGPGGA)
- {
- char checkchar = temp[1];
- for (int i = 2; temp[i] != '*'; i++)
- {
- checkchar ^= temp[i];
- }
- int checknum = 0;
- if (isalpha(temp[temp.find_first_of('*') + 1]) == 1)
- checknum += ((temp[temp.find_first_of('*') + 1] - 'A') + 10) * 16;
- else
- checknum += (temp[temp.find_first_of('*') + 1] - '0') * 16;
- if (isalpha(temp[temp.find_first_of('*') + 2]) == 1)
- checknum += ((temp[temp.find_first_of('*') + 2] - 'A') + 10);
- else
- checknum += (temp[temp.find_first_of('*') + 2] - '0');
- if (int(checkchar) == checknum)
- {
- cout << "PASS" << endl;
- unsigned int k = temp.find(',');
- while (k!= string::npos)
- {
- cout << "時間" << temp[k + 1] << temp[k + 2] << ":" << temp[k + 3] << temp[k + 4] << ":" << temp[k + 5] << temp[k + 6] << endl;
- k = string::npos;
- }
- }
- else
- cout << "ERROR" << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment