博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C/C++判断字符串是否包含某个字符串
阅读量:4493 次
发布时间:2019-06-08

本文共 996 字,大约阅读时间需要 3 分钟。

C风格

#include 
#include
#include
using namespace std;int main(){ 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 
#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;}

 

 

参考

转载于:https://www.cnblogs.com/code1992/p/11539770.html

你可能感兴趣的文章
并查集的实现
查看>>
Leetcode 350. Intersection of Two Arrays II
查看>>
EditPlus VC2010 and 2008 C/C++配置
查看>>
Practical Lessons from Predicting Clicks on Ads at Facebook
查看>>
JFrame面板
查看>>
Android自动化压力测试之Monkey Test 异常解读(五)
查看>>
Compressing Convolutional Neural Networks in the Frequency Domain 论文笔记
查看>>
设计模式:单例和多例
查看>>
Myslq 之修改数据库
查看>>
maven工程转为web工程时没有add web project capabilities选项的解决办法
查看>>
[BZOJ1192][HNOI2006]鬼谷子的钱袋
查看>>
Linux系统基础优化
查看>>
小程序开发快速入门教程(附源码)
查看>>
基于cropper.js的图片上传和裁剪
查看>>
车联网SaaS平台多租户平台技术选型参考
查看>>
我是如何快速积累工作经验
查看>>
用信号量进程同步与互斥
查看>>
随笔1
查看>>
Firebug入门指南
查看>>
POJ Minimum Cut
查看>>