Not sure what went wrong.

Hello guys,

Can someone help me with this crash. I'm not sure where in the loop the program fails.

Code Specifications:
pCWN is a vector: vector <string> pCWN; //Creating parent vector

wordsyn is a map: map<string, vector <string> > wordsyn; //create a map that associates strings with vectors


Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//Comparison loop: compare the word's synonyms and the overlap
    int parentword = 0;
    int wordnumb;
    wordnumb = pCWN.size();
    while (parentword < wordnumb)
    {
        int parentsyn = 0;
        int nextword = parentword+1;
        while (parentsyn< wordsyn[pCWN[parentword]].size())
        {
            if (find((wordsyn[pCWN[nextword]].begin()), (wordsyn[pCWN[nextword]].end()), (wordsyn[pCWN[parentword]][parentsyn])) != wordsyn[pCWN[nextword]].end())
            {
                cout << "Overlap Found." << endl;
            };

            ++parentsyn;
        };
        ++parentword;
    };


The program crashes and sends me the following error.

Error in cmd:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
MANY AND MANY "Overlap Found"...
Overlap Found.
Overlap Found.
Overlap Found.
Overlap Found.
Overlap Found.
Overlap Found.
Overlap Found.
Overlap Found.
Overlap Found.
Overlap Found.
Overlap Found.
Overlap Found.
terminate called after throwing an instance of 'std::length_error'
  what():  basic_string::_S_create

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Process returned 255 (0xFF)   execution time : 2.920 s
Press any key to continue.
 
http://www.cplusplus.com/forum/general/112111/

You try to access pCWN[nextword], in the last iteration that's out of bounds
ne555, Thank you so much for the solution. I thought that was the problem and tried solving it but wasn't sure. After your pointer I tackled that loop specifically and it workd. Thank you so much.

Furthermore, thank you for the link, it was helpful for future reference.
Topic archived. No new replies allowed.