string s = "abc";
int i = -1;
cout<<(i < s.length());
It returns false in this case. Why?
But when I write
string s = "abc";
int i = 0;
cout<<(i < s.length());
It returns true
string s = "abc";
int i = -1;
cout<<(i < s.length());
It returns false in this case. Why?
But when I write
string s = "abc";
int i = 0;
cout<<(i < s.length());
It returns true
The Problem is that you are comparing a int and a size_t, as Botje and Jana Doe pointed out. The solution is as ChrisMM pointed out:
i should be defined as size_t, as opposed to int.