How do I check for a missing character and throw an exception if the character is not in the string? I have a program where i enter an expression and I want it to display and error if the end of the expression is missing a ';'
ex. (x+2), x=2
This should throw an exception when I click enter because it is missing the ';' at the end of the expression. ie. (x+2), x=2;
I have tried to account for the missing ';' in a for loop, such as:
if (cin.peek() != ';')
but, my exception is thrown even on valid expressions that have a ';' at the end. I assume that it is because even on valid expressions that end with ';', once enter is clicked, the next character will never be ';' which is what peek() is looking for.