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里 ...
随机推荐
- Mybatis无法扫描到mapper.xml文件
在Mybatis中默认扫描与mapper包同路径下的xml,resource文件的文件夹名称不能一次性创建,如com.baidu.mapper需要创建3次 这里如果是idea开发工具,一次创建与分开创 ...
- Javascript模式(三) 策略模式
var data = { "username" : "zhangsan", "password" : "12345690" ...
- Pandoc PDF 中文
最近终于又决定(^_^)使用reStructuredText写文档了,输出PDF时的中文问题必须要解决下. 安装环境 sudo apt install texlive texlive-latex-ex ...
- ssh port forwarding
SSH端口转发,总是忘记,今天记录下.端口转发有两种,一个是local一个是remote(可能还有一种dynamic,还没有研究) 贴个链接 https://www.ssh.com/ssh/tunne ...
- 字符串转化成十六进制输出StrToHex(Delphi版、C#版)
//注意:Delphi2010以下版本默认的字符编码是ANSI,VS2010的默认编码是UTF-8,delphi版字符串事先须经过AnsiToUtf8()转码才能跟C#版得到的十六进制字符串显示结果一 ...
- 12 redis之aof日志持久化
Aof 的配置 appendonly no # 是否打开 aof日志功能 appendfsync always # 每1个命令,都立即同步到aof. 安全,速度慢 appendfsync everys ...
- java中的 equals + hashCode
[0]README 0.1)本文转自 core java volume 1, 旨在理清 equals + hashCode方法: [1]equals方法 1.1) Object中的 equals 方法 ...
- hadoop 相关工具访问端口(转)
原文:http://www.tuicool.com/articles/BB3eArJ hadoop系统部署时用到不少端口.有的是Web UI所使用的,有的是内部通信所使用的,有的是监控所使用的.实际系 ...
- ASP.NET动态网站制作(5)-- 标签语义化及知识补充
前言:这节课主要是讲标签语义化及一些知识点的补充 内容:参考老师的博文:http://www.cnblogs.com/ruanmou/p/4821894.html
- RTSP Windows专用播放器EasyPlayer : 稳定、兼容、高效、超低延时
EasyPlayer RTSP Windows专用播放器 EasyPlayer RTSP Windows 播放器是由EasyDarwin团队开发和维护的一个完善的RTSP流媒体播放器项目,视频编码支持 ...