How to search for a string in a text file and return a value in its line??

I'm very new to this so forgive me if this is a dumb question but is there a way to search for an instance of a string "XYZ" in a text file, increment to the fifth delimiter in the same line, and return that value? (similar to the VLOOKUP function in Excel)

E.g. say I have a text file with data formatted as follows (truncated):
...
GEDU,20101105,8.54,8.7,8.18,8.19,490400
GENC,20101105,7.17,7.3,7.15,7.21,3800
GENT,20101105,5.75,5.84,5.41,5.68,102100
GENZ,20101105,71.56,71.8,71.01,71.69,4584900
GEOI,20101105,18.6,19.18,18.54,18.93,78000
GEOY,20101105,45.39,45.66,45.23,45.6,139800
...

Say I have an array A[i]={GENZ, ABC, AAA, GEOY, GEDU} and an empty array B[i].

My intended algorithm is to search for a match of A[i] in the text file. If not found then B[i]=null. If found, then B[i]=the second to last value in its line in the text file. (via a for loop i->A.length

E.g. A[0]=GENZ. Find the line of GENZ in the text file and return the second to last value in that line and assign it to B[i].

In this case the second to last value in the line beginning with "GENZ" is 71.69. Thus assign B[0]=71.69.

e.g. A[4]=GEDU. GEDU is found, its second to last value if 8.19. Thus assign B[4]=8.19.

e.g. A[3]=GEOY. Its second to last value is 45.6, thus assign B[3]=45.6

The other way would be to import the text file into a set of arrays or a map container and use binary search ... but this is a HUGE data set that would take up way too much memory. I'm trying to see if there's another way without having to read in anything.

Can someone point me in the right direction?
Thanks!
read the file line by line:
http://www.cplusplus.com/doc/tutorial/files/

Then in the loop when you have your line in a string you can use find:
http://www.cplusplus.com/reference/string/string/find/
Topic archived. No new replies allowed.