C++ Help (ISO C++ forbids comparison between pointer and integer.) -
i'm trying make simple program stacks seem getting error when try run it. error says "iso c++ forbids comparison between pointer , integer.". appreciated.
my code:
#include <iostream> #include <string> using namespace std; const int maxstack = 5; struct stacktype{ string name[maxstack]; int top; }; void createstack(stacktype &stack); void destroystack(stacktype &stack); bool fullstack(stacktype stack); void push(stacktype &stack, string &newelement); bool emptystack(stacktype stack); void pop(stacktype &stack, string &poppedelement); int main(){ stacktype stack; string newelement, poppedelement; char quest; createstack(stack); cout<<"do want enter data? (y/n)"; cin>>quest; while((quest == "y" || quest == "y") && !(fullstack(stack))){ //i error on line cout<<"please enter name"; cin>>newelement; push(stack, newelement); cout<<"do want enter data? (y/n)"; cin>>quest; } cout<<endl<<endl; while(!emptystack(stack)){ pop(stack, poppedelement); cout<<poppedelement<<endl; } destroystack(stack); system("pause"); return 0; } void createstack(stacktype &stack){ stack.top = -1; } void destroystack(stacktype &stack){ stack.top = -1;; } bool fullstack(stacktype stack){ if(stack.top == maxstack - 1){ return true; }else{ return false; } } void push(stacktype &stack, string &newelement){ stack.top++; stack.name[stack.top] = newelement; } bool emptystack(stacktype stack){ if(stack.top == -1){ return true; }else{ return false; } } void pop(stacktype &stack, string &poppedelement){ poppedelement = stack.name[stack.top]; stack.top--; }
quest
char
, yet "y"
string literal type const char[2]
. when try compare these quest == "y"
, string literal converted pointer first element, , attempting compare char
pointer. that's error telling you.
instead of string literal, want character literal 'y'
, has type char
.
Comments
Post a Comment