Parsing a file results in string subscript out of range

  c++, c++14

I’m trying to parse a file , i want to print all special characters, and all words, minus spaces, this is my code

while (getline(f, line)) {
        for (int i = 0; i < line.length(); i++)
        { 
            if (line[i] != ' ') {
                if ((int(line[i]) < 'a' || int(line[i]) > 'z') && (int(line[i]) < 'A' || int(line[i]) > 'Z')) {
                    cout << line[i] << endl;
                    if (composing==true) {
                        composing = false;
                        word[poz] = 'n';
                        cout << word;
                        word.clear();
                        poz = 0;
                    }
                }
                else {
                        word[poz] = line[i];
                        poz++;
                        if (composing == false) {
                            composing = true;
                        }
                }
            }
        }
        if (composing == true) {
            word[poz] = 'n';
            cout << word;
            composing = false;
            poz = 0;
    }
}

In variable word i’m composing the words that i’m encounter, if i end the line or find a special character i print the word and start a new one.

With this implementation i’m getting:
Error message

Source: Windows Questions C++

LEAVE A COMMENT