命名空间
变体
操作

std::wcsstr

来自 cppreference.cn
< 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。 不比较终止空字符。

目录

[编辑] 参数

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

[编辑] 返回值

指向 dest 中找到的子字符串的第一个字符的指针;如果未找到此类子字符串,则为空指针。 如果 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 的文档