How can I exclude words with apostrophes when reading into a table of strings?
- by rearden
ifstream fin;
string temp;
fin.open("engldict.txt");
if(fin.is_open())
{
bool apos = false;
while(!fin.eof())
{
getline(fin, temp, '\n');
if(temp.length() > 2 && temp.length() < 7)
{
for(unsigned int i = 0; i < temp.length(); i++)
{
if(temp.c_str()[i] == '\'')
apos = true;
}
if(!apos)
dictionary.insert(temp);
}
}
}
This code gives me a runtime error: Unhandled exception at 0x00A50606 in Word Jumble.exe: 0xC0000005: Access violation reading location 0x00000014.
and throws me a break point at:
size_type size() const _NOEXCEPT
{ // return length of sequence
return (this->_Mysize);
}
within the xstring header.
This exception is thrown no matter what character I use, so long as it is present within the words I am reading in.
I am aware that it is probably a super simple fix, but I just really need another set of eyes to see it. Thanks in advance.