libc++abi.dylib: Abbruch mit uncaught exception vom Typ std::out_of_range: basic_string Fehler?

Hier ist eine Funktion, die ich Schreibe, die erhält einen string von Wörtern, getrennt durch Leerzeichen und fügt jedes Wort in ein array. Ich erhalte eine Fehlermeldung, die sagt "libc++abi.dylib: Abbruch mit uncaught exception vom Typ std::out_of_range: basic_string." Ich kann nicht scheinen, um herauszufinden, was der Fehler ist.

void lineParser(string line, string words[])
{
    string word = "";
    int array_index = 0;
    int number_of_words = 1;
    int string_index = 0;
    while (string_index < line.length())
    {
        if (line.substr(string_index,1) != " ")
        {
            int j = string_index;
            while (line.substr(j,1) != " ")
            {
                word += line.substr(j,1);
                j++;
            }
            words[array_index] = word;
            array_index++;
            word = "";
            number_of_words++;
            string_index = j;
        }
        else
        {
            string_index++;
        }
    }
}
  • Sie sollten übergeben Sie einen Verweis auf ein in der Größe veränderbares container wie std::vector, um Ihre Funktion anstatt der array-pointer.
InformationsquelleAutor thegupmasta | 2016-05-01
Schreibe einen Kommentar