Just working through a problem in Accelerated C++ and it's to determine if a string has been duplicated in a given vector. I have got the program to work and run but I also then get an error box stating "Debug Assertion Failed" - "Expression: vector subscript out of range".
The code is:
Any idea why I am getting that error message?
using namespace std;
cout << "Please enter a list of words: ";
while (cin >> data)
typedef vector<string>::size_type vec_sz;
vec_sz size = words.size();
// sort vector into alphabetic order
sort (words.begin(), words.end());
//checks for any matching words in the vector
for(int x = 0; x <= size; ++x)
if (words[x] == words[x + 1])
cout << "You have a matching pair of words: " << words[x] << " " << words[x+1];
cout << "No matches";