C++中std::string::find_last_of用法
来源:互联网 发布:如何做金融投资 知乎 编辑:程序博客网 时间:2024/06/06 07:00
最近看boost代码脑洞打开,比如这个std::string::find_last_of
:
size_t find_last_of (const string& str, size_t pos = npos) const noexcept;size_t find_last_of (const char* s, size_t pos = npos) const;size_t find_last_of (const char* s, size_t pos, size_t n) const;size_t find_last_of (char c, size_t pos = npos) const noexcept;
顾名思义,可以从后往前找匹配的字符,并且,这个字符可以以字串的形式给出,也就是只要匹配参数中字串的任意字符就返回其位置,这对于UNIX风格和Windows风格的文件夹路径处理很方便,例如:
// string::find_last_of#include <iostream> // std::cout#include <string> // std::string#include <cstddef> // std::size_tvoid SplitFilename (const std::string& str){ std::cout << "Splitting: " << str << '\n'; std::size_t found = str.find_last_of("/\\"); std::cout << " path: " << str.substr(0,found) << '\n'; std::cout << " file: " << str.substr(found+1) << '\n';}int main (){ std::string str1 ("/usr/bin/man"); std::string str2 ("c:\\windows\\winhelp.exe"); SplitFilename (str1); SplitFilename (str2); return 0;}
结果:
1 1
- C++中std::string::find_last_of用法
- C++/C++11中std::string用法汇总
- C++/STL std::string 的用法
- c++中std::string的用法总结
- string 类成员函数 find() / find_first_of() / find_last_of() 的用法详解
- C++--string--find_first_of() 和 find_last_of(),find()与npos
- std::string用法详解
- std::string的用法
- std::string用法总结
- std::string用法总结
- std::string的用法
- std::string用法总结
- std::string用法总结
- std::string用法总结
- std::string用法
- std::string用法
- std::string用法总结
- std::string用法总结
- 找出字串的最长重复子串
- IIS下虚拟目录或应用程序不继承根web.config的解决方法
- java基础回顾加强
- Mybatis接口在service注入失败的解决办法
- QT creator源码分析 ----点击search后的动作
- C++中std::string::find_last_of用法
- not a regular file问题
- CentOS7.3安装VirtualBox
- 1.Linux基本概念及操作
- 【Unity 3D学习】NGUI中自定义Toggle
- Java Instrument动态修改字节码入门-添加方法耗时监控
- i++和++i的区别
- android 内存泄漏解决方案
- ImageIO读取图片变色