title: program to check whether string contains only 1 and 0 or not?
body: <p>here is a simple code for testing a string contains only 0 and 1 or not
  ok and not in code means it contains only 0 and 1 or not respectively.
  this is giving output as not ok how?</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  void digi(string s)
  {
      bool flag1=true;
      bool flag2=true;
      int l=s.size();
      for(int i=0;i&lt;l;i++)
      {
          cout&lt;&lt;s.at(i)&lt;&lt;endl;
          if(s.at(i)!='0')
          flag1=false;
          if(s.at(i)!='1')
          flag2=false;
      }
      if(flag1==true&amp;&amp;flag2==true)
      cout&lt;&lt;"ok";
      else
      cout&lt;&lt;"not ok";
  }
  main()
  {
      string s;
      cin&gt;&gt;s;
      digi(s);
  }
  
  </code></pre>