Read a string from a text file into an array

I need to implement a priority queue and I'm trying to figure out how to read from a text file into an array. The text file will look something like

1
2
3
(arule, 12), (brule, 99), (crule, 50)
(zrule, 29)
(grule, 72), (hrule, 30)


I want to take the int value and put it into an array but I'm not sure how to separate it from the rest of the string. Any ideas?
You can read the text file into a string and search this string for occurence of substring like "rule, ".
If str is the string containing the text file:
1
2
3
4
5
6
7
int myarray[N];
i = 0;
size_t pos = 0, fpos;
while((fpos = str.find("rule, "),  pos) != npos){
   fpos += 6; //to go to the position where the numbers starts
   myarray[i++] = atoi(str.substr(fpos,fpos+2)); //to get an int from a substring
   pos = fpos;}


I can't check if I have some error in the above so be careful.

By the way why do you want to strore it to an array and not a vector?
It's for a priority queue using a heap structure and my teacher wants us to use an array. Is there anyway to just get the int without searching for the "rule, " part? I'm not sure if the input will be identical to the one I mentioned originally.
Topic archived. No new replies allowed.