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

测试结果:y

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-03
  • 2021-09-26
  • 2022-12-23
  • 2022-01-11
相关资源
相似解决方案