Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : 此檔案包含 'main' 函式。程式會於該處開始執行及結束執行。
- //
- //#include "pch.h"
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- void main()
- {
- fstream nmea_new("d:\\nmea_new.txt", ios_base::out);
- fstream file("d:\\nmea_sample.txt", ios_base::in);
- if (!file)
- cout << "smple檔案開啟失敗" << endl;
- else if (!nmea_new)
- cout << "new檔案開啟失敗" << endl;
- else {
- string s;
- string target = "GPGGA";
- int pos = 0;
- while (!file.eof()) {
- file >> s;
- if (s.find(target) != string::npos) {
- nmea_new << s << endl;
- for (int i = 1; s[i] != '*'; i++) {
- cout << s[i];
- }
- cout << ' ' << s[s.find('*') + 1] << s[s.find('*') + 2] << endl;
- int cknum = 0;
- if (s[s.find('*') + 1] >= 'A' && s[s.find('*') + 1] <= 'Z')
- cknum += (s[s.find('*') + 1] - 'A' + 10) * 16;
- else
- cknum += (s[s.find('*') + 1] - '0') * 16;
- if (s[s.find('*') + 2] >= 'A' && s[s.find('*') + 2] <= 'Z')
- cknum += s[s.find('*') + 2] - 'A' + 10;
- else
- cknum += s[s.find('*') + 2] - '0';
- int cksum = 0;
- for (int i = 1; s[i] != '*'; i++) {
- cksum ^= s[i];
- }
- // cout << "***cknum= " << cknum << endl;
- // cout << "***cksum= " << cksum << endl;
- if (cksum == cknum)
- cout << "PASS" << endl;
- else
- cout << "WRONG" << endl;
- unsigned int j, cnt = 0, pos = 0;
- if ((j = s.find(',')) != string::npos) {
- // cout << "***j= " << j << endl;
- // cout << "***pos= " << pos << endl;
- cout << "Time : " << s[s.find(',') + 1] << s[s.find(',') + 2] << " : " << s[s.find(',') + 3] << s[s.find(',') + 4] << " : " << s[s.find(',') + 5] << s[s.find(',') + 6] << endl;
- pos = j + 6;
- // cout << "***j= " << j << endl;
- // cout << "***pos= " << pos << endl;
- cout << "緯度 : " << s[s.find(',', pos) + 1] << s[s.find(',', pos) + 2] << ' ' << s[s.find(',', pos) + 3] << s[s.find(',', pos) + 4] << '.' << s[s.find('.') + 1] << s[s.find('.') + 2] << ' ' << s[s.find('.') + 3] << s[s.find('.') + 4];
- pos += 10;
- // cout << "***j= " << j << endl;
- // cout << "***pos= " << pos << endl;
- cout << ' ' << s[s.find(',', pos) + 1] << endl;
- pos += 2;
- // cout << "***j= " << j << endl;
- // cout << "***pos= " << pos << endl;
- cout << "經度 : " << s[s.find(',', pos) + 1] << s[s.find(',', pos) + 2] << s[s.find(',', pos) + 3] << ' ' << s[s.find(',', pos) + 4] << s[s.find(',', pos) + 5] << '.' << s[s.find(',', pos) + 7] << s[s.find(',', pos) + 8] << ' ' << s[s.find(',', pos) + 9] << s[s.find(',', pos) + 10];
- pos += 11;
- // cout << "***j= " << j << endl;
- // cout << "***pos= " << pos << endl;
- cout << ' ' << s[s.find(',', pos) + 1] << endl;
- pos += 2;
- // cout << "***j= " << j << endl;
- // cout << "***pos= " << pos << endl;
- }
- }
- }
- cout << "寫入完畢" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement