c++ error
hai sir
i have got a error while programming in C++ i do program for conversion of infix expression to postfix form in the convert() function i got a error void convert(const string & Infix,string & Postfix) { Stack<char> opstack; char Topsymbol,symbol; int k; for(k=0;k<sizeof(Infix);++k) { symbol=Infix[k]; if(IsOperand(symbol)) // cout<<Postfix<<symbol; //Postfix=Postfix+symbol; strcat(Postfix,symbol); else { while((!opstack.IsEmpty())&&(precedence(opstack.IsFull(),symbol))) { Topsymbol=opstack.IsFull(); opstack.pop(); // cout<<Postfix<<Topsymbol; //Postfix=Postfix+Topsymbol; strcat(Postfix,Topsymbol); } if((!opstack.IsEmpty())&&(symbol==')')) opstack.pop(); else opstack.push(symbol); } } while(!opstack.IsEmpty()) { Topsymbol=opstack.IsFull(); opstack.pop(); //cout<<Postfix<<Topsymbol; //Postfix=Postfix+Topsymbol; strcat(Postfix,Topsymbol); } } /** void operator+(string & Postfix,char ch) { strcpy(Postfix,ch); cout<<Postfix<<"\t"<<ch; strcat(Postfix,ch); return Postfix; } **/ the error is : In function ‘void convert(const std::string&, std::string&)’: error: cannot convert ‘std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ to ‘char*’ for argument ‘1’ to ‘char* strcat(char*, const char*)’ please help me to solve this error i humbly request to tell the solution |
Code:
void convert(const string & Infix,string & Postfix) Anyway... your problem is strcat doesn't take in a string object, it takes in a "c string" or char *. I'd think the + operator would be good enough for you since that is overloaded to do concatenation on the stl string class. I also recommend you start using { and } on if statements at all times. Especially in this case here: Code:
if(IsOperand(symbol)) Code:
if(IsOperand(symbol)) { |
A little cat program to show what I mean....
Code:
#include <iostream> Code:
j_shaw@jshaw ~ $ g++ -Wall -o test test.cpp |
All times are GMT -5. The time now is 11:09 AM. |