C++ string的查找函数和npos特殊值
STL中的string有6个查找函数:
1.find()
2.rfind()
从最后一个字符开始往前找。
3.find_first_of()
4.find_not_first_of()
5.find_last_of()
6.find_not_last_of()
所有这些查找函数返回值都是size_type类型(找到了)或者是一个名为 string::npos的特殊值(没找到)。
string::npos常用来表示没找到的结果或者string类型的末尾。
#include <iostream>
#include <bitset>
#include <string> int main()
{
// string search functions return npos if nothing is found
std::string s = "test";
if(s.find('a') == std::string::npos)
std::cout << "no 'a' in 'test'\n"; // functions that take string subsets as arguments
// use npos as the "all the way to the end" indicator
std::string s2(s, , std::string::npos);
std::cout << s2 << '\n'; std::bitset<> b("aaabb", std::string::npos, 'a', 'b');
std::cout << b << '\n';
}
//输出结果
/*
no 'a' in 'test'
st
00011
*/
C++ string的查找函数和npos特殊值的更多相关文章
- string类find函数返回值判定
string类find函数返回值判定 代码示例 #include<iostream> #include<cstring> using namespace std; int m ...
- C++ string类及其函数的讲解
文章来源于:http://www.cnblogs.com/hailexuexi/archive/2012/02/01/2334183.html C++中string是标准库中一种容器,相当于保存元素类 ...
- C++中string的成员函数
string类的构造函数: string(const char *s); //用c字符串s初始化 string(int n,char c); //用n个字符c初始化 此外,string类还支持默认构造 ...
- C++string类常用函数
C++string类常用函数 string类的构造函数:string(const char *s); //用c字符串s初始化string(int n,char c); //用n个字符c初 ...
- C string.h 常用函数
参考:http://womendu.iteye.com/blog/1218155 http://blog.csdn.net/zccst/article/details/4294565 还有一些,忘记了 ...
- c++中string的常用函数说明
string可以说是是字符数组的升级版,使用更加啊方便,不容易出错.本文对string的常用函数进行简单介绍,做到会用即可. string中的常用函数分为四类,即赋值,添加,比较和删除. 一.赋值 1 ...
- php中常用的字符串查找函数strstr()、strpos()实例解释
string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] ) 1.$haystack被查找的字 ...
- C/C++字符串查找函数
C/C++ string库(string.h)提供了几个字符串查找函数,如下: memchr 在指定内存里定位给定字符 strchr 在指定字符串里定位给定字符 strcspn 返回在字符串str1里 ...
- C/C++字符串查找函数 <转>
C/C++ string库(string.h)提供了几个字符串查找函数,如下: memchr 在指定内存里定位给定字符 strchr 在指定字符串里定位给定字符 strcspn 返回在字符串str1里 ...
随机推荐
- Xshell 一款很养眼的配色方案推荐
Xshell 是个很好用的在 windows 下登陆 liunx 的终端原生支持中文,配合 Xftp 管理文件,同是免费软件可远比 Putty 好用多了面对枯燥的代码,我们需要一款很养眼的配色方案来保 ...
- Java IDL与javaRMI
Registry registry = LocateRegistry.getRegistry(); registry.rebind(RemoteService.name, stub); Java 平台 ...
- Windows下Tomcat+nginx配置证书实现登录页https访问
最近公司出于安全考虑,需要将登录页做成https访问,其他页面仍采用http访问,环境是Linux平台,web服务器采用Tomcat + Nginx.之前没接触过nginx,这两天网上查资料,试了好多 ...
- Command &Prompt Here
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\shell\Command Prompt Here]@=" ...
- 安装Redis图形监控工具---RedisLive
RedisLive简介 RedisLive是一款用Python编写基于WEB的Redis图形监控工具,也是一款实时监控Redis数据的开源软件,以WEB的形式展现出redis中的key的情况,实例数据 ...
- android Bluetooth-蓝牙
bluetooth 一.开启蓝牙 1.获取BluetoothAdapter BluetoothAdapter.getDefaultAdapter() 2.判断手机设备是否 有蓝牙模块 3.开启蓝牙设备 ...
- Android开发:LocationManager获取经纬度及定位过程(附demo)
在Android开发其中.常常须要用到定位功能,尤其是依赖于地理位置功能的应用.非常多人喜欢使用百度地图,高德地图提供的sdk.开放API,可是在只须要经纬度,或者城市,街道地址等信息.并不须要提供预 ...
- 谁能举个通俗易懂的例子告诉我IAAS,SAAS,PAAS的区别?【转自知乎】
是时候祭出这篇吃货文章了: ———————————————————— ———————————————————— ———————————————————— &amp;amp;amp;lt ...
- Unix高级环境编程—进程控制(一)
一.函数fork #include<unistd.h> pid_t fork(void) ...
- Locality-sensitive hashing Pr[m(Si) = m(Sj )] = E[JSˆ (Si, Sj )] = JS(Si, Sj )
A hash function that maps names to integers from 0 to 15. There is a collision between keys "Jo ...