Reading data from file

how would I go about searching a .txt file for a string and return the number as an int that appears after the word searched for.

For example my .txt would look like:
1
2
--Name Age-- 
John 48


I Would search for John and I would like 48 outputed as an int
I think I figured it out I will search using String::Find, and grab the int using an end iterator, I was over thinking it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
string::iterator it;
string a ("John");
string b ("John 48");
size_t found;
int begin;
char b[10];
int i;

found=a.find(b);
  if (found!=string::npos){
     begin = int(found) + a.size();
     for ( it=begin; it < str.end(); it++ )
       b[it] = *it;

     i = atoi(b)  
}


Correct me if I am wrong, I am away from my computer.
Topic archived. No new replies allowed.