std:: wmemchr
From cppreference.net
|
定义于头文件
<cwchar>
|
||
|
const
wchar_t
*
wmemchr
(
const
wchar_t
*
ptr,
wchar_t
ch,
std::
size_t
count
)
;
|
(1) | |
|
wchar_t
*
wmemchr
(
wchar_t
*
ptr,
wchar_t
ch,
std::
size_t
count
)
;
|
(2) | |
在由 ptr 指向的宽字符数组的前 count 个宽字符中,定位宽字符 ch 的首次出现位置。
如果 count 为零,该函数返回空指针。
目录 |
参数
| ptr | - | 指向待检测宽字符数组的指针 |
| ch | - | 要搜索的宽字符 |
| count | - | 待检测的宽字符数量 |
返回值
指向该宽字符位置的指针,若未找到此字符则为空指针。
示例
运行此代码
#include <clocale> #include <cwchar> #include <iostream> #include <locale> int main() { const wchar_t str[] = L"诺不轻信,故人不负我\0诺不轻许,故我不负人。"; wchar_t target = L'许'; const std::size_t sz = sizeof str / sizeof *str; if (const wchar_t* result = std::wmemchr(str, target, sz)) { std::setlocale(LC_ALL, "en_US.utf8"); std::wcout.imbue(std::locale("en_US.utf8")); std::wcout << "Found '" << target << "' at position " << result - str << '\n'; } }
可能的输出:
Found '许' at position 14
参见
|
在数组中搜索字符的首次出现
(函数) |
|
|
查找字符的首次出现
(函数) |
|
|
在宽字符串中查找宽字符的首次出现
(函数) |
|
|
(C++11)
|
查找首个满足特定条件的元素
(函数模板) |
|
C 文档
关于
wmemchr
|
|