The problem is that the operator overload for
< work according to a lexicographical case sensitive comparison.
You are not obtaining a random error, the fact is that
To have a case insensitive comparison you should first convert both strings to lowercase, something like:
string lowercase; lowercase.resize(text.size()); transform(text.begin(), text.end(), lowercase.begin(), ::tolower);
And then compare them.