STL中empty()函数的误用

来源:互联网 发布:淘宝二手显示器怎么样 编辑:程序博客网 时间:2024/05/22 18:15

今日在一个项目上排查问题时,找到一个关于empty()函数误写为empty,导致出现了错误


  1. #include <iostream>  
  2. #include <string>  
  3. using namespace std;  
  4.   
  5. int main()  
  6. {  
  7.     string s = "abc";  
  8.     if(s.empty)  
  9.     {  
  10.         cout << "it is empty string" << endl;  
  11.     }  
  12.     else  
  13.     {  
  14.         cout << "not empty string" << endl;     
  15.     }  
  16.   
  17.     return 0;    
  18. }  
结果是it is empty string.

看来写代码还是要认真的,不能有半点马虎。好了,今天周五,也要下班了,赶紧吃点饭。

原创粉丝点击