samedi 25 novembre 2017

ifstream reading apostrophe crashes

I'm using this code:

Every time I read the word "doesn't" from a text file, I get this error:

std::string word;
while (f >> word) {
    good_input = true;
    for (int i = 0; i < word.length(); ++i) {
        if (ispunct(word.at(i))) {
            word.erase(i--, 1);
        }
        else if (isupper(word.at(i))){
            word.at(i) = tolower(word.at(i));
        }
    }

Debug Assertion Failed!
Program: directory\SortingWords(Length).exe
File: minkernel\crts\ucrt\src\appcrt\convert\istype.cpp
Line: 36
Expression: c >= -1 && c <= 255
For more information please visit... [etc.]

When I click "abort", my program exits with code 3?

It looks like it's got something to do with the apostrophe maybe? This code works find for all other words in my document up until this one. And works great with documents that don't include apostrophes, yet they include plenty of other punctuation...

I tried changing the encoding of the text file (simply made with notepad), but that didn't help. Generally found lots of complaints about apostrophes but no working answers. Can anyone help me figure out what's going on?

Aucun commentaire:

Enregistrer un commentaire