Outputting a character from a stack outputs the ASCII instead

I put a + in a stack, and I'm trying to use cout to display stack.top(), which is the +, but it's outputting 43 instead.

This isn't my code, but it's essentially what I'm doing:

1
2
3
4
char ch = '+';
stack<int> myStack;
myStack.push(ch);
cout << myStack.top();


If I need to display my real code because the problem might lie elsewhere, then I don't mind

I'm also putting integers in my stack
because you use int as the template argument ?

1
2
3
4
5
6
7
#include <iostream>

int main()
{
    int i = '+';
    std::cout << i; // prints 43
}
Last edited on
Topic archived. No new replies allowed.