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

std::wcschr

Defined in header <cwchar>

const wchar_t* wcschr( const wchar_t* str, wchar_t ch );

wchar_t* wcschr( wchar_t* str, wchar_t ch );

查找宽字符的第一次出现。ch在宽串中,指的是...str...

参数

str

-

pointer to the null-terminated wide string to be analyzed

ch

-

wide character to search for

返回值

中找到的字符的指针。str,或NULL如果找不到这样的角色。

二次

代码语言:javascript
复制
#include <iostream>
#include <cwchar>
#include <locale>
 
int main()
{
    wchar_t arr[] = L"招き猫 кошка";
    const wchar_t* cat = std::wcschr(arr, L'猫');
    const wchar_t* dog = std::wcschr(arr, L'犬');
 
    std::cout.imbue(std::locale("en_US.utf8"));
 
    if(cat)
        std::cout << "The character 猫 found at position " << cat - arr << '\n';
    else
        std::cout << "The character 猫 not found\n";
 
    if(dog)
        std::cout << "The character 犬 found at position " << dog - arr << '\n';
    else
        std::cout << "The character 犬 not found\n";
}

二次

产出:

二次

代码语言:javascript
复制
The character 猫 found at position 2
The character 犬 not found

二次

另见

find

find characters in the string (public member function of std::basic_string)

strchr

finds the first occurrence of a character (function)

wcsrchr

finds the last occurrence of a wide character in a wide string (function)

wcspbrk

finds the first location of any wide character in one wide string, in another wide string (function)

c Wcschr文件

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

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

扫码关注腾讯云开发者

领取腾讯云代金券