std::strrchr(3)
π NAME π
okay bestie, welcome to the std::strrchr(3) page in the C++ Standard Libary manual β yes, that's the header spelling, iykyk. The NAME is literally std::strrchr - std::strrchr, and this whole page is about finding the last match like it's the main character. π
πΈ Synopsis πΈ
Defined in header <cstring> β that's where it lives, bestie. β¨
const char* strrchr( const char* str, int ch );
char* strrchr( char* str, int ch );
So what does it do? It finds the last occurrence of ch (after conversion to char) in the byte string pointed to by str. The terminating null character is considered to be a part of the string and can be found if searching for '\0'. That's the whole vibe check. π₯
π Parameters π
strβ pointer to the null-terminated byte string to be analyzedchβ character to search for
π Return value π
Pointer to the found character in str, or null pointer if no such character is found. That's the whole return tea. π«Ά
π¦ Example π¦
Here's the example, no cap β run this code:
// Run this code
#include <cstring>
#include <iostream>
int main()
{
char input[] = "/home/user/hello.c";
char* output = std::strrchr(input, '/');
if (output)
std::cout << output + 1 << '\n';
}
π Output π
hello.c
π See also π
strchrβ finds the first occurrence of a character (function)wcsrchrβ finds the last occurrence of a wide character in a wide string (function)rfindβ find the last occurrence of a substring (public member function ofstd::basic_string<CharT,Traits,Allocator>)- C documentation for
strrchr
source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::strrchr(3) β bye bestie, go find that last slash πβ¨π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms