C++ <cwchar> - wcsrchr() Function
The C++ <cwchar> wcsrchr() function is used to find the last occurrence of a wide character wc in the wide string pointed to by ws. The terminating null character is considered as a part of the string and can be found if searching for '\0'.
The function returns pointer to the last occurrence of wc in ws, or null pointer if wc is not found in ws.
Syntax
const wchar_t* wcsrchr (const wchar_t* ws, wchar_t wc); wchar_t* wcsrchr (wchar_t* ws, wchar_t wc);
Parameters
ws |
Specify pointer to the null-terminated wide string to be searched in. |
wc |
Specify the wide character to searched for. |
Return Value
Returns pointer to the last occurrence of wc in ws, or null pointer if wc is not found in ws.
Example:
The example below shows the usage of wcsrchr() function.
#include <iostream> #include <cwchar> using namespace std; int main (){ wchar_t MyStr[100] = L"To be, or not to be, that is the question."; wchar_t * search; //searching for last occurrences of 'o' in MyStr search = wcsrchr(MyStr, L'o'); //displaying the result if(search != NULL) wcout<<"Found at: "<<(search-MyStr+1); else wcout<<"Not Found.\n"; return 0; }
The output of the above code will be:
Found at: 40
❮ C++ <cwchar> Library