C风格
#include string a=\"abcdefghigklmn\"; char *b=\"def\"; char *c=\"123\"; if(strstr(a.c_str(), b) == NULL)//在a中查找b,如果不存在, cout << \"not found\\n\";//输出结果。 else//否则存在。 cout <<\"found\\n\"; //输出结果。 if(strstr(a.c_str(), c) == NULL)//在a中查找b,如果不存在, cout << \"not found\\n\";//输出结果。 else//否则存在。 cout <<\"found\\n\"; //输出结果。 return 0;} C++风格 #include using namespace std;int main(){ string a=\"abcdefghigklmn\"; string b=\"def\"; string c=\"123\"; string::size_type idx; idx=a.find(b);//在a中查找b. if(idx == string::npos )//不存在。 cout << \"not found\\n\"; else//存在。 cout <<\"found\\n\"; idx=a.find(c);//在a中查找c。 if(idx == string::npos )//不存在。 cout << \"not found\\n\"; else//存在。 cout <<\"found\\n\"; return 0;} 因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- yrrf.cn 版权所有 赣ICP备2024042794号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务