Namespaces
Variants

std:: wcsstr

From cppreference.net
定义于头文件 <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 的首次出现位置。终止空字符不参与比较。

目录

参数

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

返回值

指向目标字符串中找到的子串首字符的指针,若未找到该子串则返回空指针。如果 src 指向空字符串,则返回 dest

示例

#include <clocale>
#include <cwchar>
#include <iostream>
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)) != nullptr; ++result)
        std::wcout << L"Found: \"" << result << L"\"\n";
}

可能的输出:

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

另请参阅

查找给定子串的首次出现
( std::basic_string<CharT,Traits,Allocator> 的公开成员函数)
查找字符子串的首次出现
(函数)
在宽字符串中查找宽字符的首次出现
(函数)
在宽字符串中查找宽字符的最后一次出现
(函数)
C 文档 关于 wcsstr