For const string
reference variable str
in the following piece of code:
Works well: for(int i=0; str[i]; i++)
Throws error: for(int i=0; *(str+i); i++)
Error: error: no match for 'operator+' (operand types are 'const string {aka const std::basic_string}' and 'int')
// Return true if str is binary, else false
bool isBinary(const string &str)
{
for(int i=0; *(str+i); i++){
if(str[i]!='0' && str[i]!='1')
return false;
}
return true;
}
P.S.: I can understand this might be a naive question, but then I would be happy to be redirected to useful sources too!