在线文档教程
C++
字符串 | Strings

std::wmemchr

STD:Wmemchr

Defined in header
const wchar_t* wmemchr( const wchar_t* ptr, wchar_t ch, std::size_t count
wchar_t* wmemchr( wchar_t* ptr, wchar_t ch, std::size_t count

定位宽字符的第一次出现ch在开头count所指向的宽字符数组的宽字符。ptr...

如果count函数返回一个空指针。

参数

ptr-pointer to the wide character array to be examined
ch-wide character to search for
count-number of wide characters to examine

返回值

指向宽字符位置的指针,如果找不到宽字符,则为空指针。

二次

#include <iostream> #include <cwchar> #include <clocale> #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

二次

另见

memchrsearches an array for the first occurrence of a character (function)
strchrfinds the first occurrence of a character (function)
wcschrfinds the first occurrence of a wide character in a wide string (function)
findfind_iffind_if_not (C++11)finds the first element satisfying specific criteria (function template)

C.wmemchr文件

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/string/Wide/wmemchr