C++ string find的误用

来源:互联网 发布:志鸿优化设计系列 编辑:程序博客网 时间:2024/05/21 09:48

        最近在代码中, 看到类似这样一段代码:

#include <iostream>#include <string>using namespace std;int main(){string s = "abc";if(s.find("x")){cout << "yes" << endl;}else{cout << "no" << endl;}    return 0;  }
      结果是: yes


      刚好与程序的本意违背, 大家思考一下, 为什么? 要注意什么?





0 0
原创粉丝点击