C/C中的wcsrchr()函数++

这个 wcsrchr() 函数是C/C++中的一个内置函数,用于搜索宽字符串中最后出现的宽字符。它是在 cwchar 头文件在C++中。

null

语法 :

wcsrchr(str, ch)

参数 :该函数接受两个参数,如下所述。

  • str :指定要搜索的以null结尾的宽字符串。
  • 中国 :它指定要搜索的宽字符。

返回值 :函数返回两种类型的值:

  • 如果 中国 如果找到,函数将返回指向 中国 在里面 str .
  • 如果没有找到,则返回空指针。

下面的程序说明了上述功能。

方案1 :

// C++ program to illustrate the
// wcsrchr() function
#include <cwchar>
#include <iostream>
using namespace std;
int main()
{
wchar_t str[] = L "GeeksforGeeks" ;
wchar_t ch = L 'e' ;
wchar_t * p = wcsrchr(str, ch);
if (p)
wcout << L "Last position of " << ch << L " in ""
<< str << "" is " << (p - str);
else
wcout << ch << L " is not present in "" << str << L """ ;
return 0;
}


输出:

Last position of e in "GeeksforGeeks" is 10

方案2 :

// C++ program to illustrate the
// wcsrchr() function
#include <cwchar>
#include <iostream>
using namespace std;
int main()
{
wchar_t str[] = L "Ishwar Gupta" ;
wchar_t ch = L 'o' ;
wchar_t * p = wcsrchr(str, ch);
if (p)
wcout << L "Last position of " << ch << L " in ""
<< str << "" is " << (p - str);
else
wcout << ch << L " is not present in "" << str << L """ ;
return 0;
}


输出:

o is not present in "Ishwar Gupta"

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享