У вас 2 ошибки. Во-первых, чтение вашей входной строки в ваш стек, как минимум, это будет очень запутанным и в худшем случае не сработает.
Во-вторых, при проверке совпадения тегов вы проверяете, совпадает ли открывающая скобка с закрывающий, это никогда не будет правдой, вам нужно проверить, что открывающая скобка имеет тот же тип, что и закрывающая.
Один из способов устранения обеих ошибок:
int main()
{
// match variable to keep track that closing bracket and opening brackets are in sequence
char match = '\0';
bool isMatching = true;
// resetting the stack variables and attributes
stack.top = -1;
stack.array = new char[1000];
std::string input;
cout << "Enter the Expression to match the parenthesis: ";
cin >> input;
std::map<char, char> opening = { { ')', '(' }, { '}', '{' }, { ']', '[' } };
// traversing through the character array and matching parenthesis
for (char ch : input)
{
// if character is an opening bracket
if (ch == '(' || ch == '{' || ch == '[')
push(ch);
// if character is a closing bracket
else if (ch == ')' || ch == '}' || ch == ']')
{
match = pop();
auto open = opening.find(ch);
if (open == opening.end() || open->second != match )
isMatching = false;
}
}
if (isMatching == true)
cout << "Parenthesis Matched" << endl;
else
cout << "Not matched" << endl;
delete[] stack.array;
return 0;
}