Importing data from text to array

closed account (GyhX92yv)
I'm trying to write a program that will import data from a text file, pass that data into a set of functions that I have created, and export the processed data into a new text file. The data that I have is in the following format, and repeats around 15000 times:
Run 141544 event 7
Njets 1
m1: pt,eta,phi,m= 281.327 -0.489914 1.12498 0.1 dptinv: 0.000406393
m2: pt,eta,phi,m= 238.38 0.128715 -2.07527 0.1 dptinv: 0.000399279

Run 141572 event 2
Njets 2
m1: pt,eta,phi,m= 243.862 0.363307 1.14333 0.1 dptinv: 0.000426386
m2: pt,eta,phi,m= 219.52 -0.0366446 -2.15279 0.1 dptinv: 0.000426963

Each entry consists of four lines, followed by a blank line that separates it from the following entry. The data that I need to import is the entire first line of each entry, and the values on the 3rd and 4th lines (not including the dptinv value), which are delimited by spaces. I would like to store the values for each event in an array, so they could be input into functions. Would using a counter variable be the best way to do this? If so, how would it be implemented?
Last edited on
I was thinking of using getline(data,arr[100],'\n') and inputfile >> ws at the end to skip the whitespaces. you basically read from the input file and store it into an array.
Topic archived. No new replies allowed.