I am running into an error during my program's runtime:
"Debug Assertion Failed! ... Expression: string subscript out of range."
This is happening in my for loop when my if statement attempts to check if the character at 'i' in the string isDelimiter() or isOperator(). I am passing the char 'check' as an attribute, and in the comments I have made sure that 'check' is grabbing the correct character. I've been working on this issue for a while and I can't seem to resolve it.
EDITED AT BOTTOM
string inputLine = "";
string inputString = "";
int main()
{
ifstream input("input.txt");
getline(input, inputLine);
if (input.is_open())
{
while (!input.eof())
{
getline(input, inputLine);
for (int i = 0; i<inputLine.length(); i++)
{
char check = inputLine[i];
//cout << check << "\n"; // test for 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 for
} // end while
//input.close();
}
else cout << "Unable to open file.";
return 0;
}
Here are the isDelimiter() and 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 help is appreciated!
EDIT::
After reviewing my code some more I realized the mistake, but I still have another. That runtime error was because in my isOperator() and isDelimiter() functions, I was checking inputString[c] rather than just 'c'. Silly mistake, I know. However, although there is no longer an error, the program still skips checking the isOperator() and isDelimiter() methods, and only goes into the else statement when it reads a ' '. Why isn't it going into my else statement for operators and delimiters?