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?
#include<iostream>
using namespace std;
void digi(string s)
{
bool flag1=true;
bool flag2=true;
int l=s.size();
for(int i=0;i<l;i++)
{
cout<<s.at(i)<<endl;
if(s.at(i)!='0')
flag1=false;
if(s.at(i)!='1')
flag2=false;
}
if(flag1==true&&flag2==true)
cout<<"ok";
else
cout<<"not ok";
}
main()
{
string s;
cin>>s;
digi(s);
}