++




- 4


short line_pos = 0; //

// iterate through each line of text

for ( ; line_pos < text_file->size(); ++line_pos )

// textline:

// word_pos:

short word_pos = 0;

string textline = (*text_file) [ line_pos ];

string::size_type pos = 0, prev_pos = 0;

while (( pos = textline.find_first_of( ' ', pos ))

!= string::npos )

{

//

words->push_back(

textline.substr( prev_pos, pos - prev_pos ));

//

locations->push_back(

make_pair( line_pos, word_pos ));

//

++word_pos; prev_pos = ++pos;

}

//

words->push_back(

textline.substr( prev_pos, pos - prev_pos ));

locations->push_back(

make_pair( line_pos, word_pos ));

}

return new text_loc( words, locations );

}

main() :

int main()

{

vector<string> *text_file = retrieve_text();

text_loc *text_locations = separate_words( text_file );

// ...

}

, separate_words():

textline: Alice Emma has long flowing red hair. Her Daddy

says

eol: 52 pos: 5 line: 0 word: 0 substring: Alice

eol: 52 pos: 10 line: 0 word: 1 substring: Emma

eol: 52 pos: 14 line: 0 word: 2 substring: has

eol: 52 pos: 19 line: 0 word: 3 substring: long

eol: 52 pos: 27 line: 0 word: 4 substring: flowing

eol: 52 pos: 31 line: 0 word: 5 substring: red

eol: 52 pos: 37 line: 0 word: 6 substring: hair.

eol: 52 pos: 41 line: 0 word: 7 substring: Her

eol: 52 pos: 47 line: 0 word: 8 substring: Daddy

last word on line substring: says