Just curious why 'stack' marked as the tag of this question? Seems in C++ vector could solve it smoothly, Could anyone share a stack approach/ Implementation?
Stack is listed because you will need a stack-like operation to keep the previous string for "..". For vector, you will be using things like pop_back(), that's your stack operation. So what you are describing is "stack" tag.