I am trying to compare strings in cpp but i got a bunch of errors like
no match for 'operator=='
invalid conversion from char to const char *
I'm implementing two functions :
1) compare the strings and search for brackets, then return a bool.
2) compare the strings and search for arithmetic operators, then return a bool.
Here's my code :
bool isBracket(const string b) { if(b == ")" || b=="(") return true; else return false; } bool isOperator(const string op) { string ops= "*+-^/"; for(int i = 0; i < ops.length(); i++) { if (op == ops[i]) return true; else return false; } } int main() { string exp="(a+b)"; for(int i=0; i < exp.size(); i++) { cout<<exp[i]<<endl; if(isBracket(exp[i])) cout<<"bracket found"<<endl; if(isOperator(exp[i])) cout<<"operator found"<<endl; } return 0; }
isBracketfunction can be simplified toreturn (b == "(" || b == ")");ops[i]is achar. There's no comparison betweenstd::stringand a singlechar.