这个 wmemchr() C/C++中的函数在宽字符块中定位字符。此函数用于在第一个 号码 块的宽字符由 ptr 第一次出现 中国 ,并返回指向它的指针。
null
语法:
const wchar_t*wmemchr(const wchar_t*ptr,wchar_t ch,size_t num) 或 wchar_t*wmemchr(wchar_t*ptr,wchar_t ch,size_t num)
参数: 该函数接受三个强制性参数,如下所述:
- ptr: 指定指向要搜索的字符数组的指针。
- 中国: 指定要定位的字符。
- 号码: 指定要比较的wchar_t类型的元素数。
返回值: 该函数返回两个值,如下所示:
- 成功后,它返回一个指向字符数组位置的指针。
- 否则,将返回空指针。
以下程序说明了上述功能:
方案1:
C++
// C++ program to illustrate // wmemchr() function #include <bits/stdc++.h> using namespace std; int main() { // initialize the string to be scanned wchar_t ptr[] = L "GeeksForGeeks" ; // character to be searched for wchar_t ch = L 'o' ; // length, till the character to be search for is 8 // run the function to check if the character is present bool look = wmemchr(ptr, ch, 8); if (look) wcout << "'" << ch << "'" << L " is present in first " << 8 << L " characters of "" << ptr << """ ; else wcout << "'" << ch << "'" << L " is not present in first " << 8 << L " characters of "" << ptr << """ ; return 0; } |
输出:
'o' is present in first 8 characters of "GeeksForGeeks"
项目2:
C++
// C++ program to illustrate // wmemchr() function #include <bits/stdc++.h> using namespace std; int main() { // initialize the string to be scanned wchar_t ptr[] = L "GFG" ; // character to be searched for wchar_t ch = L 'p' ; // length, till the character to be search for is 3 // run the function to check if the character is present bool look = wmemchr(ptr, ch, 3); if (look) wcout << "'" << ch << "'" << L " is present in first " << 3 << L " characters of "" << ptr << """ ; else wcout << "'" << ch << "'" << L " is not present in first " << 3 << L " characters of "" << ptr << """ ; return 0; } |
输出:
'p' is not present in first 3 characters of "GFG"
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END