Search code examples
c++stackcstring

C++ - Pushing a C-String onto a Template Stack


I am sure that for most this is a very easy question. But I am writing a token recoginzer for XML in c++ and I am using a stack to make sure there are matching begining and end tags. Well my tags are c strings...

char BeginTag[MAX];

I am trying to push that onto my template stack. But I am unsure what type to pass the stack. I have tried...

stack<char> TagStack;

But that doesn't work. I have tried a few other solutions alos but none seem to work. Can someone help me?


Solution

  • Arrays aren't assignable, so can't be used as a container value type.

    You could define a struct containing an array, though, and use that:

    struct Tag {
        char name[MAX];
    };
    
    stack<Tag> TagStack;
    

    Or just use a std::string for your tags.