CppDS.com

C++ 98 11 14 17 20 手册

std::wcsstr

来自cppreference.com
< cpp‎ | string‎ | wide
定义于头文件 <cwchar>
const wchar_t* wcsstr( const wchar_t* dest, const wchar_t* src );
      wchar_t* wcsstr(       wchar_t* dest, const wchar_t* src );

寻找 dest 所指的空终止宽字符串在 src 所指的空终止宽字符串中的首次出现。不比较空终止字符。

srcdest 不是指向空终止字节字符串的指针,则行为未定义。

参数

dest - 指向要检验的空终止字节字符串的指针
src - 指向要搜索的空终止宽字符串的指针

返回值

指向于 dest 中找到的子串首字符的指针,或若找不到该子串则为空指针。若 src 指向空字符串,则返回 dest

示例

#include <iostream>
#include <cwchar>
#include <clocale>
 
int main()
{
    wchar_t const* origin = L"アルファ, ベータ, ガンマ, アルファ, ベータ, ガンマ.";
    wchar_t const* target = L"ベータ";
    wchar_t const* result = origin;
 
    std::setlocale(LC_ALL, "en_US.utf8");
    std::wcout << L"Substring to find: \"" << target << L"\"\n"
               << L"String to search: " << origin << L"\n\n";
 
    for (; (result = std::wcsstr(result, target)) != NULL; ++result)
        std::wcout << L"found: " << result << '\n';
}

可能的输出:

Substring to find: "ベータ"
String to search: アルファ, ベータ, ガンマ, アルファ, ベータ, ガンマ.
 
found: ベータ, ガンマ, アルファ, ベータ, ガンマ.
found: ベータ, ガンマ.

参阅

于字符串中寻找字符
(std::basic_string<CharT,Traits,Allocator> 的公开成员函数)
寻找字符子串的首次出现
(函数)
寻找宽字符串中宽字符的首次出现
(函数)
在宽字符串中寻找宽字符的最后一次出现
(函数)
关闭