为什么if(int类型的负数<字符串stl的length())永远为true

int a=-1;
string str="abc";
if(a<str.length()) cout<<"y"<<endl;
else cout<<"x"<<endl;

测试结果:y

原因:length()返回的是unsigned类型的,int会被强制转换为unsigned,-1会被转换为4294967295

posted @ 2020-10-06 22:59  肥斯大只仔  阅读(114)  评论(0编辑  收藏  举报