//代码如下//
#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了。
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
下次吧string::npos写前面,如果忘了就会报错。
------解决方案--------------------------------------------------------
单步调试和设断点调试是程序员必须掌握的技能之一。