I have an assignment where I to make a stack based calculator. I know there are other post explaining this, and I have the stack template made. My real problem for some reason or another, I am having trouble reading a string of numbers / char into a stack. At first I tried using a string object, then I tried using a char array. Neither have worked for me. Can anyone give me some tips or examples of how to read a string of char & int into a stack. It would be very helpful. Thanks

Do you mean a std::stack? You can just push and pop anything in/out it. It's actually quite simple...

#include <iostream>
#include <stack>
#include <string>

using namespace std;

void ShowStack(stack<string> in)
{
    while (!in.empty())
    {
        cout << in.top() << '\n';
        in.pop();
    }
}
int main()
{
    char s1[] = "I'm a char array!";
    string s2= "I'm a std::string!";
    stack<string> my_stack;
    my_stack.push(s1);
    my_stack.push(s2);
    ShowStack(my_stack);
    return 0;
}

You can always use other kinds of stacks then my string-stack in above example.

If you created somesort of stack yourself, you'll have to post the code to get some advice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.