string::find()--关键字符串定位

本文详细解析了C++标准库中string类的find成员函数的使用方法及参数含义,包括如何查找字符串、字符和指定长度的子串,并在给定起始位置开始搜索。通过实例演示,帮助读者掌握这一常用操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 语法: 

1 1.size_type source_str.find( const basic_string &str, size_type index );
2 2.size_type  source_str.find( const char *str, size_type index );
3 3.size_type  source_str.find( const char *str, size_type index, size_type length );
4 4.size_type  source_str.find( char ch, size_type index );

1、2.返回str在字符串source_str中第一次出现的位置(从index开始查找)。如果没找到则返回string::npos,

3.返回str在字符串source_str中第一次出现的位置(从index开始查找,长度为length)。如果没找到就返回string::npos,

4.返回字符ch在字符串source_str中第一次出现的位置(从index开始查找)。如果没找到就返回string::npos

 

转载于:https://www.cnblogs.com/kevinGaoblog/archive/2012/04/21/2461510.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值