当前位置: 代码迷 >> C++ >> c++查找函数find()错误
  详细解决方案

c++查找函数find()错误

热度:3484   发布时间:2013-02-26 00:00:00.0
c++查找函数find()异常
//代码如下//
#include <iostream>
#include <string>
using namespace std;

int main()
{
string name("the catche rin the rye");
string::type_size p=name.find("rye");
if(p=string::npos)
{
cout<<"the rye couldn't be find"<<endl;

}

else
cout<<"the rye find at p="<<p<<endl;
system("pause");
return 0;



}
//编译没错,但输出"the rye counldn't be find"//

------解决方案--------------------------------------------------------
你把if(p==string::npos)中的==误写为=了,改为==就OK了。
------解决方案--------------------------------------------------------
引用:
你把if(p==string::npos)中的==误写为=了,改为==就OK了。

------解决方案--------------------------------------------------------
下次吧string::npos写前面,如果忘了就会报错。
------解决方案--------------------------------------------------------
单步调试和设断点调试是程序员必须掌握的技能之一。
  相关解决方案