在线文档教程
C++
字符串 | Strings

std::memchr

STD::memchr

Defined in header
const void* memchr( const void* ptr, int ch, std::size_t count
void* memchr( void* ptr, int ch, std::size_t count

皈依chunsigned char,并在初始值中定位该值的第一次出现。count字符%28解释为unsigned char所指对象的%29ptr...

参数

ptr-pointer to the object to be examined
ch-character to search for
count-number of characters to examine

返回值

指向字符位置的指针,或NULL如果找不到这样的角色。

搜索一组字符。

二次

#include <iostream> #include <cstring> int main() { char arr[] = {'a','\0','a','A','a','a','A','a'}; char *pc = (char*)std::memchr(arr,'A',sizeof arr if (pc != NULL) std::cout << "search character found\n"; else std::cout << "search character not found\n"; }

二次

产出:

二次

search character found

二次

另见

strchrfinds the first occurrence of a character (function)
findfind_iffind_if_not (C++11)finds the first element satisfying specific criteria (function template)

c备忘录文件

© cppreference.com

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

http://en.cppreference.com/w/cpp/string/字节/memchr