std::wmemchr
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    |   定义于头文件  <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 );  | 
||
于 ptr 所指向的宽字符数组的首 count 个宽字符中,定位宽字符 ch 的首次出现。
若 count 为零,则函数返回空指针。
参数
| ptr | - | 指向要检验的宽字符数组的指针 | 
| ch | - | 要搜索的宽字符 | 
| count | - | 要检验的宽字符数 | 
返回值
指向宽字符位置的指针,或若找不到这种字符则为空指针。
示例
运行此代码
#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"; } }
可能的输出:
Found '许' at position 14
参阅
|   在数组中搜索字符的首次出现  (函数)  | |
|   寻找字符的首次出现  (函数)  | |
|   寻找宽字符串中宽字符的首次出现  (函数)  | |
|    (C++11)  | 
   寻找首个满足特定判别标准的元素   (函数模板)  |