std:: wmemchr
From zh.cppreference.net
C++
Text processing library
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
Null-terminated wide strings
| Functions | ||||||||||||||||||||||||||
| Character classification | ||||||||||||||||||||||||||
| Character manipulation | ||||||||||||||||||||||||||
| Conversions to numeric formats | ||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||
| String manipulation | ||||||||||||||||||||||||||
| String examination | ||||||||||||||||||||||||||
| Array manipulation | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
定义于头文件
<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 为零,该函数返回空指针。
目录参数
返回值指向该宽字符位置的指针,若未找到此字符则为空指针。 示例
运行此代码
#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 参阅
| |||||||||||||||||||||