Checking Characters in a string

I have been coding in c++ for just over a month. I am still learning the basics. I am trying to take a string which represents a binary number and indicate if there are characters other than 1's or 0's in that particular string. It should return a boolean value. I understand the concept but i am struggling with the implementation of the code. Any ideas?
Something like that:
1
2
3
4
5
6
7
8
9
bool is_binary(const std::string &str)
{
  for(const char ch : str)
  {
    if((ch != '0') and (ch != '1'))
      return false;
  }
  return true;
}
Topic archived. No new replies allowed.