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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With