首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

str!=NULL为何会出错解决办法

2012-03-25 
str!NULL为何会出错bool check(string str){if(str!NULL)..........}这是我程序里一部分if(str!NULL)这

str!=NULL为何会出错
bool check(string str)
{
  if(str!=NULL)

  ..........

}


这是我程序里一部分
if(str!=NULL)这条语句总是报错,不知什么原因,原来可以用的
错误信息是:error C2678: binary '!=' : no operator defined which takes a left-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)

求高手看下什么原因

[解决办法]
string又不是指针,最好不要这样用吧,试试用empty成员函数
[解决办法]
没有定义的“class std::basic_string”类型的左操作运算符(或者没有定义的可接受转换)

没这样用过
可以用if(str.Empty())

或者if(0 == str.Length())

热点排行
Bad Request.