c++ - Expression: string subscript out of range. Attribute passing issue? -


i running error during program's runtime:
"debug assertion failed! ... expression: string subscript out of range."

this happening in loop when if statement attempts check if character @ 'i' in string isdelimiter() or isoperator(). passing char 'check' attribute, , in comments have made sure 'check' grabbing correct character. i've been working on issue while , can't seem resolve it.

edited @ bottom

    string inputline = "";     string inputstring = "";      int main()     {         ifstream input("input.txt");         getline(input, inputline);          if (input.is_open())         {             while (!input.eof())             {                 getline(input, inputline);                  (int = 0; i<inputline.length(); i++)                 {                     char check = inputline[i];                     //cout << check << "\n"; // test correct character                      if ((inputline[i] != ' ') || (inputline[i] != isdelimiter(check)) || (inputline[i] != isoperator(check)))                     {                         inputstring = inputstring + inputline[i];                         //cout << lexer(inputstring) << "\n";                         //cout << inputstring;                     } // end if                     else                     {                         cout << lexer(inputstring);                         if (inputline[i] == isdelimiter(i))                     cout << inputline[i] + "\tdelimiter";                         if (inputline[i] == isoperator(i))                             cout << inputline[i] + "\toperator";                         inputstring = "";                     } // end else                     //cout << inputstring << "\n";                 } // end             } // end while             //input.close();         }         else cout << "unable open file.";          return 0;     } 

here isdelimiter() , isoperator() methods.

    bool isoperator(char c)     {         if ((inputline[c] == '+') || (inputline[c] == '-') || (inputline[c] == '*') || (inputline[c] == '/') || (inputline[c] == '=') || (inputline[c] == '%') || (inputline[c] == '<') || (inputline[c] == '>'))             return true;         else             return false;     }      bool isdelimiter(char c)     {         if ((inputline[c] == ';') || (inputline[c] == '(') || (inputline[c] == ')') || (inputline[c] == ','))             return true;         else             return false;     } 

any appreciated!

edit::

after reviewing code more realized mistake, still have another. runtime error because in isoperator() , isdelimiter() functions, checking inputstring[c] rather 'c'. silly mistake, know. however, although there no longer error, program still skips checking isoperator() , isdelimiter() methods, , goes else statement when reads ' '. why isn't going else statement operators , delimiters?

your functions take char, change them int:

bool isdelimiter(char c) //should int {     if ((inputline[c] == ';') || (inputline[c] == '(') || (inputline[c] == ')') || (inputline[c] == ','))         return true;     else         return false; } 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -