My .txt file is in something like this:
...
...
Start 75
23 55 00 00 00 48 00 05 -10 -53
21 45 03 00 00 00 12 06 -08 09
03 55 00 00 00 88 10 75 -10 -53
51 35 00 34 50 00 12 06 100 09
Start 76
33 55 00 50 00 48 80 05 -10 -93
61 15 33 00 30 00 12 00 -08 19
91 35 10 32 50 00 12 06 -30 09
Start 77
...
...
The identifier 'Start' is used to separate two bunches of data. The number of rows between identifiers are not always constant. Basically many rows of zeroes are rejected while taking data, so I cannot read a fixed number of lines between two occurrances of 'Start'.
For now, I use this code to read it line by line:
#include <fstream>
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
using namespace std;
int main(int argc,char **argv) {
string filename;
ifstream file(filename.c_str());
char word[BUFSIZ];
char start, end;
if (argc == 2) {
filename = argv[1];}
else {
cout<<"Usage: " << argv[0] << "filename" << endl;
exit (-1);}
if (file.is_open()) {
string line;
string numbers;
vector<int> myNumbers;
int count = 0;
while(file.good()) {
getline(file, line);
//-------I am really lost here.
//-------I tried many approaches but the bunches seem to get mixed up
//if (count < 2){
// if (line.find("Start") != string::npos){
// count++; }
// else {
// numbers.append(line);
// numbers.append("\n--");}
//}
//else {
// cout << endl << numbers << endl;
// count = 0;
// numbers.clear();}
}
file.close();}
}
I am trying to group the line
at first occurrance of 'Start' (using a string for now to group together all the lines) until another occurrance of 'Start' is encountered. I will convert all those values in their order to a vector
for storing next. I am not that good at C++, so stuck here and unsure about the implementation of this step, or if a better way exists. Also I must mention that the .txt file has around a million lines in total. I need help on how to group the rows in bunches between two 'Start' strings?