Namespaces
Variants
Views
Actions

std::strrchr

From cppreference.com
< cpp‎ | string‎ | byte
Revision as of 19:13, 7 May 2013 by Cubbi (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <cstring>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td class="t-dcl-nopad">
const char* strrchr( const char* str, int ch );
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td class="t-dcl-nopad">
      char* strrchr(       char* str, int ch );
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

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'.

Contents

Parameters

str - pointer to the null-terminated byte string to be analyzed
ch - character to search for

Return value

Pointer to the found character in str, or null pointer if no such character is found.

Example

#include <iostream>
#include <cstring>
 
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

Template:cpp/string/byte/dcl list strchrTemplate:cpp/string/wide/dcl list wcsrchrTemplate:cpp/string/basic string/dcl list rfind
C documentation for strrchr