I am using C++ and i want to push strings in stack like push int
in stacks.
For Example
3."stackoverflow"
2."is"
1."Best"
0."site"
at every index of stack I want to push a string. How can I do this?
I am using C++ and i want to push strings in stack like push int
in stacks.
For Example
3."stackoverflow"
2."is"
1."Best"
0."site"
at every index of stack I want to push a string. How can I do this?
Using STL, for example:
#include <stack>
std::stack<std::string> s;
s.push("A");
s.push("B");
s.push("C");
s.push("D");
Check the sgi STL reference for more information.
Totally agree with Ton van den Heuvel, however you said
"at every index of stack I want to push a string"
What do you mean "at every index"? You should know that once the strings are in the stack, you can only access the top string and there is no access by index in a stack. If that's what you need, use std::vector instead.
There is some misunderstanding here. I want to push strings in stack. just like to push as integers. push("Hello"); push("world");
give me the code plz for this.