std::strrchr
来自cppreference.com
在标头 <cstring> 定义 | ||
constchar* strrchr(constchar* str, int ch ); | ||
char* strrchr( char* str, int ch ); | ||
寻找 ch(转换到 char 后)在 str 所指向的空终止字节串中的最后出现。若搜索 '\0',则认为终止空字符为字符串的一部分,而且能找到。
目录 |
[编辑]参数
str | - | 指向要分析的空终止字节字符串的指针 |
ch | - | 要搜索的字符 |
[编辑]返回值
指向 str 中找到的字符的指针,或若找不到这种字符则为空指针。
[编辑]示例
运行此代码
#include <cstring>#include <iostream> 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> 的公开成员函数) | |
strrchr 的 C 文档 |