Ok, I input a string of characters from the keyboard. I need to know how to read that string into a stack. Everytime I do it seems to be reading the whole string in as one character. HOw can I get it to read it one character at a time.
Printable View
Ok, I input a string of characters from the keyboard. I need to know how to read that string into a stack. Everytime I do it seems to be reading the whole string in as one character. HOw can I get it to read it one character at a time.
Here is a sample of my code which I know you will probably laugh at but the people who taught me C++ were jackasses and never taught me how to use template classes or anything else I need to know right now.
int main ()
{//Opens Main Program
string name2_reverse;
cout<<"Please enter a string of characters to have reversed.\n";
cin>>name2_reverse;
stack<string,deque<string>> Mystack;
int i;
for (i=0; i < 10; i++)
{
Mystack.push(string(name2_reverse));
cout << Mystack.top() <<endl;
}
//int a;
//Mystack.empty()=a;
//for (a != 0)
//{
// cout << Mystack.top() << endl;
// Mystack.pop();
// }
cout<<"Reversed this string = " << name2_reverse <<"\n";
getch();
}//Closes Main Program
String is a generic term. Stack is a generic term. There are countless implementations of strings and stacks. So until you post more specific descriptions, preferably with code, I can only give you a generic answer:Quote:
Ok, I input a string of characters from the keyboard. I need to know how to read that string into a stack.
When you have read the string, take a for loop that runs from the beginning of the string to the end of the string. In each loop, get the character at this position in the string and put it on the stack.