std::wmemchr
来自 cppreference.cn
定义于头文件 <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 文档 for wmemchr
|