I am trying to produce some code in C++ that will be able to scan through a mixed document and extract specific lines of data. The document will look like this (below) but will have hundreds of these 'begin measurement' and 'end measurement' markers with different text within each one.
/begin MEASUREMENT
E2_PCU_90V "The 90v rail PWM trim value"
UWORD
CM_136
1 0
0 65535
ECU_ADDRESS 0x0006B5C6
/end MEASUREMENT
/begin MEASUREMENT
test_Array_Fill _APV "Temporary unsigned "
ULONG
CM_134
1 0
0 4294967295
ECU_ADDRESS 0x0006B5C8
/end MEASUREMENT
I have written a bit of code that will scan through the document and find every 'begin measurement' and print it in a different file. I am now stuck as I need it to extract the lines in-between the 'begin measurement' and 'end measurement' and print them in the other file.
I hope that I have explained my problem enough for you to help me.
Thank you
Lana
/begin MEASUREMENT
E2_PCU_90V "The 90v rail PWM trim value"
UWORD
CM_136
1 0
0 65535
ECU_ADDRESS 0x0006B5C6
/end MEASUREMENT
/begin MEASUREMENT
test_Array_Fill _APV "Temporary unsigned "
ULONG
CM_134
1 0
0 4294967295
ECU_ADDRESS 0x0006B5C8
/end MEASUREMENT
I have written a bit of code that will scan through the document and find every 'begin measurement' and print it in a different file. I am now stuck as I need it to extract the lines in-between the 'begin measurement' and 'end measurement' and print them in the other file.
Code:
#include <iostream> #include <fstream> #include <string> using namespace std; void main () { string find_this_string = "begin MEASUREMENT"; fstream datain, dataout; string current_line_in_file; cout << "Reading infomation from an A2L file \n"; datain.open("examplea2l.txt",fstream::in); dataout.open("librarya.txt",fstream::out); while (getline(datain, current_line_in_file, '\n')) { string::size_type pos = current_line_in_file.find(find_this_string,0); if (pos != string::npos) { dataout << current_line_in_file << "\n"; } else { /* do nothing */ } } datain.close(); dataout.close(); }
Thank you
Lana
Comment