decode a text file

This is my first post. I'm trying to write a simple program to open a .txt file which would contain an aviation forecast and decode it into simple english that anyone could understand.

I've found code on how to open the text file and display it in the console, but I'm stumped on how to pick individual components in the text and then convert it to my new output.

What would I use to read the text and how would I implement my changes? Just a few hints would nice as I like the challenge and I'll learn much more than being totally spoonfed. Thanks.

Here is an example of what I wish to do:


TAF YBCV 270020Z 2702/2714
23007KT CAVOK
FM270800 22005KT CAVOK
RMK
T 17 19 16 12 Q 1019 1017 1018 1020



I wish to decode that text into:

Terminal Area Forecast Birdsville
Issued 0020 UTC 27/08/2010
Valid from 0200 to 1400
Wind 230 at 07 knots
Ceiling and visibility OK

From 0800 UTC Wind 220 at 05 knots
Ceiling and Visibilty OK
Remarks:
Temperatures 17 19 16 12
QNH's 1019 1017 1018 1020
Clearly you have to look up code names somewhere. Do you have access to these? Do you have a description of the file format?
The help is appreciated :).

What is an example of a piece of code that would replace one string with another?

I think I could be on the right track with "replace" in the string library but I am unsure how to implement it.

http://www.cplusplus.com/reference/string/string/replace/

For example I wish to replace "CAVOK" with "Ceiling and Visibility OK"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

int main () {
  string line;
  ifstream myfile ("example.txt");
  if (myfile.is_open())
  {
    while (! myfile.eof() )
    {
      getline (myfile,line);
      cout << line << endl;
      
    }
    myfile.close();
  }

  else cout << "Unable to open file"; 
  
  //decode section
  string oCAVOK = "CAVOK";
  string nCAVOK = "Ceiling and visibility ok";
  //replace strings


  
  
  
  cout << "end of document\n";
  
  cin.get();

  return 0;
}

Last edited on
You'll have to create a new file with the translation. This is because the writing functions available simply run over any pre-existing data. So changing "CAVOK" to "Ceiling and visibility ok" would actually probably cause this:

TAF YBCV 270020Z 2702/2714
23007KT Ceiling and visibility okT Ceiling and visibility ok Q 1019 1017 1018 1020

So, instead, create a new file with the translation.

Simply read the file word for word checking against the database
1
2
3
originalFile >> str;
if(str=="CAVOK")
   translation << "Ceiling and visibility ok"


or something of the sort.
Topic archived. No new replies allowed.