首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::wmemchr

Defined in header <cwchar>

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

返回值

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

二次

代码语言:javascript
复制
#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";
    }
}

二次

可能的产出:

二次

代码语言:javascript
复制
Found '许' at position 14

二次

另见

memchr

searches an array for the first occurrence of a character (function)

strchr

finds the first occurrence of a character (function)

wcschr

finds 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文件

代码语言:txt
复制
 © cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券