I need to do a stack of strings but im getting problems can anyone help
heres what I have so far:
#include <iostream>
#include <string>
using namespace std;
class StringStack
{
private: string *stackArray;
int stackVal;
int top;
public: StringStack(string);
~StringStack();
void push(string);
void pop(string &);
bool isFull();
bool isEmpty();
};
StringStack::StringStack(string value)
{
stackArray = new string[value];
stackVal = value;
top = -1;
}
StringStack::~StringStack()
{
delete[] stackArray;
}
void StringStack::push(string val)
{
if(isFull())
{
cout<< "The stack is full. \n";
}
else
{
top++;
stackArray[top]= val;
}
}
void StringStack::pop(string &val)
{
if(isEmpty())
{
cout<<"The stack is empty. \n";
}
else
{
val=stackArray[top];
top--;
}
}
bool StringStack::isFull()
{
bool status;
if (top==stackVal -1)
status = true;
else
status = false;
return status;
}
bool StringStack::isEmpty()
{
bool status;
if (top==-1)
status= true;
else
status = false;
return status;
}
int main()
{string val;
StringStack stack(val);
string catchVar;
cout<< "Pushing AAAA\n";
stack.push("AAAA");
cout<< "Pushing BBBB\n";
stack.push("BBBB");
cout<<"Pushing CCCC\n";
stack.push("CCCC");
cout<<"Popping... \n";
stack.pop(catchVar);
cout<<catchVar<<endl;
stack.pop(catchVar);
cout<<catchVar<<endl;
stack.pop(catchVar);
cout<<catchVar<<endl;
stack.pop(catchVar);
return 0;
}
The errors im getting:
Error 1 error C2440: 'initializing' : cannot convert from 'std::string' to 'size_t' g:\pf iii\stacks\stacks\stack.cpp 23
Error 2 error C2440: '=' : cannot convert from 'std::string' to 'int' g:\pf iii\stacks\stacks\stack.cpp 24