今天在代码中用到string的这个方法,一不小心就用错了。

这是http://www.cplusplus.com/关于这个方法的解释。

Find character in string from the end

Searches the string for the last character that matches any of the characters specified in its arguments.

When pos is specified, the search only includes characters at or before position pos, ignoring any possible occurrences after pos.

这里解释说:在指定的字符串中搜索最靠后的任意匹配的字符或者字符串,如果指定了pos,那么搜索范围只会在pos之前以及pos处的字符,不会考虑之后的字符。


我就错了这个地方,我以为搜索不会搜索pos处的字符呢

要小心这些细节处的东西,否则会让你很难受呢,感觉自己代码写对了,但是结果就是不对,主要还是对C++库的使用不熟练。

string::find_last_of的更多相关文章

  1. string find_last_of 用法

    int find_first_of(char c, int start = 0):              查找字符串中第1个出现的c,由位置start开始.              如果有匹配, ...

  2. C++string中find,find_first_of和find_last_of的用法

    1. size_t find (const string& str, size_t pos = 0) str.find(str1) 说明:从pos(默认是是0,即从头开始查找)开始查找,找到第 ...

  3. leetcode345——Reverse Vowels of a String(C++)

    Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...

  4. C++ string 类详解

    字符串是存储在内存的连续字节中的一系列字符.C++ 处理字符串的方式有两种,一种来自 C 语言,常被称为 C-风格字符串,另一种是基于 string 类库的字符串处理方式.C 风格字符串的处理可以参考 ...

  5. std::string::find_last_not_of

    public member function <string> std::string::find_last_not_of C++98 C++11 string (1) size_t fi ...

  6. 关于string类中find函数的讲解

    以下所讲的所有的string查找函数,都有唯一的返回类型,那就是size_type,即一个无符号整数(按打印出来的算).若查找成功,返回按查找规则找到的第一个字符或子串的位置:若查找失败,返回npos ...

  7. C++ string类型小结

    目录 构造函数 string.append() string.assign() string.at() string.back() string.begin() string.capasity() s ...

  8. C++编程优化心得(持续更新)

    1. 对齐原则.比如64位总线,每次寻址读取8B.编程时注意变量地址,尽量消耗总线最少的寻址次数.堆内存申请时,系统严格按照对齐原则分配,故而使用时候也尽量不要跨寻址边界. 2. 需要的时候,可为了效 ...

  9. c++中级 STL基础学习(二)

    deque 和vector差不多,可以在前端后端插入,一般用deque取代vector,vector只能在后端插入push_back().deque还可以push_front(),但是deque后端插 ...

随机推荐

  1. 【计算几何】 Codeforces Beta Round #67 (Div. 2) E. Ship's Shortest Path

    读懂题意其实是模板题.就是细节略多. #include<cstdio> #include<cmath> #include<algorithm> using name ...

  2. 【DFS】bzoj2079 [Poi2010]Guilds

    对一棵树黑白染色一定符合题意. 图一定有生成树. 因此,仅有一个孤立节点的联通块不合题意. DFS. #include<cstdio> using namespace std; int n ...

  3. JAVA 基本概念和编码规范

    概括性描述:一个Java程序可以认为是一系列对象的集合,而这些对象通过调用彼此的方法来协同工作. 基本概念: 下面简要介绍下类.对象.方法和属性的概念. 对象:对象是类的一个实例,有状态和行为.例如, ...

  4. JQuery获取第几个元素和判断元素在第几个

    HTML代码: <ul> <li>jQuery判断当前元素是第几个元素示例</li> <li>jQuery获取第N个元素示例</li> &l ...

  5. BigDecimal的精度舍入模式详解

    BigDecimal舍入模式介绍: 舍入模式在java.math.RoundingMode 里面: RoundingMode.CEILING :向正无限大方向舍入的舍入模式.如果结果为正,则舍入行为类 ...

  6. [Java基础] java多线程关于消费者和生产者

    多线程: 生产与消费 1.生产者Producer生产produce产品,并将产品放到库存inventory里:同时消费者Consumer从库存inventory里消费consume产品. 2.库存in ...

  7. supervisord的环境变量的设置

    在python中引用jar包,使用java的功能,需要使用三方包:pyjnius from jnius import autoclass 需要java环境,因此需要设置JAVA_HOME环境变量. 但 ...

  8. python - ImportError: No module named pywintypes

    must restart the python shell to avoid this issue after pywin32 installed

  9. 一、ELKStack介绍与入门实践

    第1章 ELKStack 对于日志来说,最常见的需求就是收集.存储.查询.展示,开源社区正好有相对应的开源项目:logstash(收集).elasticsearch(存储+搜索).kibana(展示) ...

  10. More is better——并查集求最大集合(王道)

    Description Mr Wang wants some boys to help him with a project. Because the project is rather comple ...