help reviewing for my exam

hello all, this is my first post my roommate and I are stuck.

heres the code.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
string get_data (const string &incoming)
int p = incoming.find("<data>");
if (p==string::npos)
    return("0");

int q = incoming.find("</data>", p+6); // p or p+1, or p+6 would do
if (q==string::npos)
    return("0");

return(
        incoming.substr(
                         p+6
                             q-p-6)     );



What exactly is the "p" doing in the code, what is its purpose??

anyhelp would be greatly appreciated.

Thanks,
John
Last edited on
closed account (z05DSL3A)
p is being used as an index to mark the begining of the <data> tag in the incoming string.
Topic archived. No new replies allowed.