std::strrchr
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    |   定义于头文件  <cstring>
  | 
||
|   const char* strrchr( const char* str, int ch );  | 
||
|         char* strrchr(       char* str, int ch );  | 
||
寻找 ch (转换到 char 后)在 str 所指向的空终止字节串中的最后出现。若搜索 '\0' ,则认为终止空字符为字符串的一部分,而且能找到。
参数
| str | - | 指向要分析的空终止字节字符串的指针 | 
| ch | - | 要搜索的字符 | 
返回值
指向 str 中找到的字符的指针,或若找不到这种字符则为空指针。
示例
运行此代码
#include <iostream> #include <cstring> int main() { char input[] = "/home/user/hello.c"; char* output = std::strrchr(input, '/'); if(output) std::cout << output+1 << '\n'; }
输出:
hello.c
参阅
|   寻找字符的首次出现  (函数)  | |
|   在宽字符串中寻找宽字符的最后一次出现  (函数)  | |
|   寻找子串的最后一次出现  ( std::basic_string<CharT,Traits,Allocator> 的公开成员函数)  |