I have a string that needs to be check for a valid postfix expression.
A valid postfix string is 1 2 + but not 1 2+ since each character needs a space. Also, since it's a string, you can enter words, but they should return -1 for this function.
I have tried using vector array with strings and checking for valid ints, but when the user enters letters this obviously creates a problem.
string postfix = "1 2 +"; // valid
string postfix = "soemthing"; // error
string postfix = "1 2+" ; // error since there is no space.
if (!isdigit(postfix[0]))
return -1;
int t;
string line = "55 124 4 5";
std::vector <int> ints;
std::istringstream iss ( line, std::istringstream::in);
int main() {
while (iss >> t )
{
ints.push_back(t);
}
if (!digit(ints[0]) || !digit(ints[0]))
return -1;
}
~