Hello, I'm having trouble with stacks. For some reason I can't use them unless I use the line
using namespace std;
Is this normal or is this something I am doing wrong. I am also trying to read out whats on a stack in the same order I put it in without changing the stack. I figured the simplest way to do this would be to make another stack and read whats on the first stack as a value parameter in a function. Is my thinking correct. Here is my code. I have some errors that I can't get rid of all dealing with the stack. The first is on the line
void switch_stack(stack);
Can I pass a stack as an input parameter or am I doing something wrong. Here is the complete code so far.
#include <iostream>
#include <conio.h>
#include <string>
#include <stack>
using namespace std;
void switch_stack(stack); //Function to move items from 1 stack to the other.
int main (void)
{//Opens Main Program
char i;
string reverse;
stack <char> Mystack;
cout<<"Enter String to go on stack.\n";
cin>>reverse;
getch();
for (i=0; i<reverse.length(); ++i)
{
Mystack.push(reverse[i]);
cout<<"Character: " <<reverse[i]<<" Was pushed onto the stack\n";
getch();
}
switch_stack(Mystack);
while (!Mystack.empty())
{//Opens While Loop
cout<<Mystack.top();
Mystack.pop();
}//Closes While Loop
return 0;
}//Closes Main Program
void switch_stack(stack Mystack1)
{//Opens Switch_stack Function
stack <char> Mystack2;
char j;
char c;
while (!Mystack.empty())
{//Opens for Loop
c=Mystack.top;
Mystack2.push(c);
Mystack.pop;
}//Closes for Loop
while (!Mystack2.empty())
{//Opens While Loop
cout<<Mystack2.top();
Mystack2.pop();
}//Closes While Loop
}//Closes Switch_Stack Function