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

Recommended Answers

All 2 Replies

I need to do a stack of strings but im getting problems can anyone help

...

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

stackArray = new string[value]; String is not an array, and value is not a number. Look up new again.

Error 2 error C2440: '=' : cannot convert from 'std::string' to 'int' g:\pf iii\stacks\stacks\stack.cpp 24

stackVal = value; What type of variables are these?

Did you not see the answers when you asked this same question yesterday?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.